@fougere/http 0.6.0-alpha.0 → 0.7.0-alpha.0
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/dist/express.d.ts +3 -33
- package/dist/express.d.ts.map +1 -1
- package/dist/express.js +3 -33
- package/dist/express.js.map +1 -1
- package/dist/fastify.d.ts +1 -11
- package/dist/fastify.d.ts.map +1 -1
- package/dist/fastify.js +1 -11
- package/dist/fastify.js.map +1 -1
- package/dist/hono.d.ts +1 -11
- package/dist/hono.d.ts.map +1 -1
- package/dist/hono.js +1 -11
- package/dist/hono.js.map +1 -1
- package/dist/logger.d.ts +1 -9
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +1 -9
- package/dist/logger.js.map +1 -1
- package/dist/router.d.ts +4 -39
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +3 -27
- package/dist/router.js.map +1 -1
- package/package.json +1 -1
- package/src/express.ts +3 -33
- package/src/fastify.ts +1 -11
- package/src/hono.ts +1 -11
- package/src/logger.ts +1 -9
- package/src/router.ts +4 -39
package/dist/express.d.ts
CHANGED
|
@@ -1,16 +1,4 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Express adapter — bridges an Express app to the HttpRouter interface.
|
|
3
|
-
*
|
|
4
|
-
* The one that is not Web-standard, and that is the whole substance of this file.
|
|
5
|
-
* Hono hands over `c.req.raw`, Fastify parses the body for us; Express hands a
|
|
6
|
-
* Node `IncomingMessage` and parses nothing unless the app happens to have mounted
|
|
7
|
-
* `express.json()`. So the conversion lives here — read the stream when nobody
|
|
8
|
-
* else did, and build the `Request` the interface promises.
|
|
9
|
-
*
|
|
10
|
-
* Working with or without `express.json()` is deliberate: an adapter that only
|
|
11
|
-
* works when the host app is configured a particular way is a footgun, and this
|
|
12
|
-
* one is meant to be dropped into an app that already exists.
|
|
13
|
-
*/
|
|
1
|
+
/** Express adapter — bridges an Express app to the HttpRouter interface. */
|
|
14
2
|
import { type HttpRouter } from './router.js';
|
|
15
3
|
interface ExpressLike {
|
|
16
4
|
use(...handlers: Function[]): void;
|
|
@@ -22,27 +10,9 @@ interface ExpressLike {
|
|
|
22
10
|
}
|
|
23
11
|
/** Drain the Node stream. Only reached when no body parser ran before us. */
|
|
24
12
|
export declare function readRawBody(req: any): Promise<string>;
|
|
25
|
-
/**
|
|
26
|
-
* The JSON body of an Express request, whoever parsed it.
|
|
27
|
-
*
|
|
28
|
-
* Exported because two consumers need the same Express fact: this adapter, and the
|
|
29
|
-
* middlewares in `@fougere/app/express`. `express.json()` may or may not have run —
|
|
30
|
-
* an adapter that only works when the host app is configured a particular way is a
|
|
31
|
-
* footgun — so this trusts `req.body` when it is there and drains the stream when it
|
|
32
|
-
* is not. Parsed once per request: a drained stream answers empty the second time.
|
|
33
|
-
*/
|
|
13
|
+
/** The JSON body of an Express request, whoever parsed it. */
|
|
34
14
|
export declare function readExpressBody(req: any): Promise<unknown>;
|
|
35
|
-
/**
|
|
36
|
-
* Create an HttpRouter backed by an Express app.
|
|
37
|
-
*
|
|
38
|
-
* ```ts
|
|
39
|
-
* import express from 'express'
|
|
40
|
-
* import { createExpressRouter } from '@fougere/http'
|
|
41
|
-
*
|
|
42
|
-
* const app = express()
|
|
43
|
-
* const router = createExpressRouter(app)
|
|
44
|
-
* ```
|
|
45
|
-
*/
|
|
15
|
+
/** Create an HttpRouter backed by an Express app. */
|
|
46
16
|
export declare function createExpressRouter(app: ExpressLike): HttpRouter;
|
|
47
17
|
export {};
|
|
48
18
|
//# sourceMappingURL=express.d.ts.map
|
package/dist/express.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"express.d.ts","sourceRoot":"","sources":["../src/express.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"express.d.ts","sourceRoot":"","sources":["../src/express.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,OAAO,EAA6B,KAAK,UAAU,EAA4F,MAAM,aAAa,CAAC;AAEnK,UAAU,WAAW;IACnB,GAAG,CAAC,GAAG,QAAQ,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;IACnC,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC3C,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC5C,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC3C,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC7C,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,GAAG,IAAI,CAAC;CAC/C;AAeD,6EAA6E;AAC7E,wBAAgB,WAAW,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC,CAkBrD;AAED,8DAA8D;AAC9D,wBAAgB,eAAe,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,CAqB1D;AAoDD,qDAAqD;AACrD,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,WAAW,GAAG,UAAU,CAuChE"}
|
package/dist/express.js
CHANGED
|
@@ -1,16 +1,4 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Express adapter — bridges an Express app to the HttpRouter interface.
|
|
3
|
-
*
|
|
4
|
-
* The one that is not Web-standard, and that is the whole substance of this file.
|
|
5
|
-
* Hono hands over `c.req.raw`, Fastify parses the body for us; Express hands a
|
|
6
|
-
* Node `IncomingMessage` and parses nothing unless the app happens to have mounted
|
|
7
|
-
* `express.json()`. So the conversion lives here — read the stream when nobody
|
|
8
|
-
* else did, and build the `Request` the interface promises.
|
|
9
|
-
*
|
|
10
|
-
* Working with or without `express.json()` is deliberate: an adapter that only
|
|
11
|
-
* works when the host app is configured a particular way is a footgun, and this
|
|
12
|
-
* one is meant to be dropped into an app that already exists.
|
|
13
|
-
*/
|
|
1
|
+
/** Express adapter — bridges an Express app to the HttpRouter interface. */
|
|
14
2
|
import { MalformedJsonError, chain } from './router.js';
|
|
15
3
|
const METHOD_MAP = {
|
|
16
4
|
GET: 'get',
|
|
@@ -45,15 +33,7 @@ export function readRawBody(req) {
|
|
|
45
33
|
req.on('error', reject);
|
|
46
34
|
});
|
|
47
35
|
}
|
|
48
|
-
/**
|
|
49
|
-
* The JSON body of an Express request, whoever parsed it.
|
|
50
|
-
*
|
|
51
|
-
* Exported because two consumers need the same Express fact: this adapter, and the
|
|
52
|
-
* middlewares in `@fougere/app/express`. `express.json()` may or may not have run —
|
|
53
|
-
* an adapter that only works when the host app is configured a particular way is a
|
|
54
|
-
* footgun — so this trusts `req.body` when it is there and drains the stream when it
|
|
55
|
-
* is not. Parsed once per request: a drained stream answers empty the second time.
|
|
56
|
-
*/
|
|
36
|
+
/** The JSON body of an Express request, whoever parsed it. */
|
|
57
37
|
export function readExpressBody(req) {
|
|
58
38
|
if (req.__fougereBody)
|
|
59
39
|
return req.__fougereBody;
|
|
@@ -126,17 +106,7 @@ function sendResponse(res, result) {
|
|
|
126
106
|
else
|
|
127
107
|
res.json(result.data);
|
|
128
108
|
}
|
|
129
|
-
/**
|
|
130
|
-
* Create an HttpRouter backed by an Express app.
|
|
131
|
-
*
|
|
132
|
-
* ```ts
|
|
133
|
-
* import express from 'express'
|
|
134
|
-
* import { createExpressRouter } from '@fougere/http'
|
|
135
|
-
*
|
|
136
|
-
* const app = express()
|
|
137
|
-
* const router = createExpressRouter(app)
|
|
138
|
-
* ```
|
|
139
|
-
*/
|
|
109
|
+
/** Create an HttpRouter backed by an Express app. */
|
|
140
110
|
export function createExpressRouter(app) {
|
|
141
111
|
const globalMiddlewares = [];
|
|
142
112
|
const scopedMiddlewares = [];
|
package/dist/express.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"express.js","sourceRoot":"","sources":["../src/express.ts"],"names":[],"mappings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, handler: Function): void;
|
|
8
8
|
delete(path: string, handler: Function): void;
|
|
9
9
|
}
|
|
10
|
-
/**
|
|
11
|
-
* Create an HttpRouter backed by a Fastify server.
|
|
12
|
-
*
|
|
13
|
-
* ```ts
|
|
14
|
-
* import Fastify from 'fastify'
|
|
15
|
-
* import { createFastifyRouter } from '@fougere/http'
|
|
16
|
-
*
|
|
17
|
-
* const fastify = Fastify()
|
|
18
|
-
* const router = createFastifyRouter(fastify)
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
10
|
+
/** Create an HttpRouter backed by a Fastify server. */
|
|
21
11
|
export declare function createFastifyRouter(server: FastifyLike): HttpRouter;
|
|
22
12
|
export {};
|
|
23
13
|
//# sourceMappingURL=fastify.d.ts.map
|
package/dist/fastify.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fastify.d.ts","sourceRoot":"","sources":["../src/fastify.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAmE,MAAM,aAAa,CAAC;AAE/G,UAAU,WAAW;IACnB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC/C,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC3C,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC5C,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC3C,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC7C,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,GAAG,IAAI,CAAC;CAC/C;AAoDD
|
|
1
|
+
{"version":3,"file":"fastify.d.ts","sourceRoot":"","sources":["../src/fastify.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAmE,MAAM,aAAa,CAAC;AAE/G,UAAU,WAAW;IACnB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC/C,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC3C,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC5C,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC3C,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC7C,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,GAAG,IAAI,CAAC;CAC/C;AAoDD,uDAAuD;AACvD,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,WAAW,GAAG,UAAU,CAyBnE"}
|
package/dist/fastify.js
CHANGED
|
@@ -48,17 +48,7 @@ function sendResponse(reply, result) {
|
|
|
48
48
|
// and the content-type rides in `headers` — the producer states it, we do not guess.
|
|
49
49
|
reply.status(result.status).send(result.data);
|
|
50
50
|
}
|
|
51
|
-
/**
|
|
52
|
-
* Create an HttpRouter backed by a Fastify server.
|
|
53
|
-
*
|
|
54
|
-
* ```ts
|
|
55
|
-
* import Fastify from 'fastify'
|
|
56
|
-
* import { createFastifyRouter } from '@fougere/http'
|
|
57
|
-
*
|
|
58
|
-
* const fastify = Fastify()
|
|
59
|
-
* const router = createFastifyRouter(fastify)
|
|
60
|
-
* ```
|
|
61
|
-
*/
|
|
51
|
+
/** Create an HttpRouter backed by a Fastify server. */
|
|
62
52
|
export function createFastifyRouter(server) {
|
|
63
53
|
const globalMiddlewares = [];
|
|
64
54
|
const scopedMiddlewares = [];
|
package/dist/fastify.js.map
CHANGED
|
@@ -1 +1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path: string, handler: Function): void;
|
|
12
12
|
delete(path: string, handler: Function): void;
|
|
13
13
|
}
|
|
14
|
-
/**
|
|
15
|
-
* Create an HttpRouter backed by a Hono app.
|
|
16
|
-
*
|
|
17
|
-
* ```ts
|
|
18
|
-
* import { Hono } from 'hono'
|
|
19
|
-
* import { createHonoRouter } from '@fougere/http'
|
|
20
|
-
*
|
|
21
|
-
* const hono = new Hono()
|
|
22
|
-
* const router = createHonoRouter(hono)
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
14
|
+
/** Create an HttpRouter backed by a Hono app. */
|
|
25
15
|
export declare function createHonoRouter(app: HonoLike): HttpRouter;
|
|
26
16
|
export {};
|
|
27
17
|
//# sourceMappingURL=hono.d.ts.map
|
package/dist/hono.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hono.d.ts","sourceRoot":"","sources":["../src/hono.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAEL,KAAK,UAAU,EAEhB,MAAM,aAAa,CAAC;AAErB,UAAU,QAAQ;IAChB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,QAAQ,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;IACjD,GAAG,CAAC,GAAG,QAAQ,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;IACnC,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC3C,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC5C,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC3C,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC7C,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,GAAG,IAAI,CAAC;CAC/C;AAyDD
|
|
1
|
+
{"version":3,"file":"hono.d.ts","sourceRoot":"","sources":["../src/hono.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAEL,KAAK,UAAU,EAEhB,MAAM,aAAa,CAAC;AAErB,UAAU,QAAQ;IAChB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,QAAQ,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;IACjD,GAAG,CAAC,GAAG,QAAQ,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;IACnC,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC3C,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC5C,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC3C,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC7C,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,GAAG,IAAI,CAAC;CAC/C;AAyDD,iDAAiD;AACjD,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,QAAQ,GAAG,UAAU,CAiD1D"}
|
package/dist/hono.js
CHANGED
|
@@ -57,17 +57,7 @@ function sendResponse(c, result) {
|
|
|
57
57
|
function malformedJsonResponse(c) {
|
|
58
58
|
return sendResponse(c, { status: 400, data: { code: 'BAD_REQUEST', message: 'Malformed JSON body' } });
|
|
59
59
|
}
|
|
60
|
-
/**
|
|
61
|
-
* Create an HttpRouter backed by a Hono app.
|
|
62
|
-
*
|
|
63
|
-
* ```ts
|
|
64
|
-
* import { Hono } from 'hono'
|
|
65
|
-
* import { createHonoRouter } from '@fougere/http'
|
|
66
|
-
*
|
|
67
|
-
* const hono = new Hono()
|
|
68
|
-
* const router = createHonoRouter(hono)
|
|
69
|
-
* ```
|
|
70
|
-
*/
|
|
60
|
+
/** Create an HttpRouter backed by a Hono app. */
|
|
71
61
|
export function createHonoRouter(app) {
|
|
72
62
|
return {
|
|
73
63
|
use(...args) {
|
package/dist/hono.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hono.js","sourceRoot":"","sources":["../src/hono.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EACL,kBAAkB,EAAE,WAAW,GAGhC,MAAM,aAAa,CAAC;AAYrB,MAAM,UAAU,GAAoE;IAClF,GAAG,EAAE,KAAK;IACV,IAAI,EAAE,MAAM;IACZ,GAAG,EAAE,KAAK;IACV,KAAK,EAAE,OAAO;IACd,MAAM,EAAE,QAAQ;CACjB,CAAC;AAEF,SAAS,YAAY,CAAC,CAAM;IAC1B,sEAAsE;IACtE,MAAM,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,eAAe,CAAC,IAAI,EAAE,CAAC;IAC3C,CAAC,CAAC,GAAG,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC;IAC9B,OAAO;QACL,OAAO,EAAE,CAAC,CAAC,GAAG,CAAC,GAAG;QAClB,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,WAAW,EAAgB;QAChD,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,IAAI;QAChB,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE;QAC3B,KAAK,EAAE,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE;QAC1B,IAAI,EAAE,KAAK,IAAI,EAAE;YACf,MAAM,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;YAC1C,MAAM,WAAW,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,CAA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C,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/logger.d.ts
CHANGED
|
@@ -6,15 +6,7 @@ interface LoggerLike {
|
|
|
6
6
|
info(msg: string, ...args: unknown[]): void;
|
|
7
7
|
warn(msg: string, ...args: unknown[]): void;
|
|
8
8
|
}
|
|
9
|
-
/**
|
|
10
|
-
* HTTP request logger — logs method, path, status, and duration.
|
|
11
|
-
*
|
|
12
|
-
* ```ts
|
|
13
|
-
* import { httpLogger } from '@fougere/http'
|
|
14
|
-
*
|
|
15
|
-
* router.use(httpLogger(logger))
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
9
|
+
/** HTTP request logger — logs method, path, status, and duration. */
|
|
18
10
|
export declare function httpLogger(logger: LoggerLike): Middleware;
|
|
19
11
|
export {};
|
|
20
12
|
//# sourceMappingURL=logger.d.ts.map
|
package/dist/logger.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,UAAU,UAAU;IAClB,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAC5C,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;CAC7C;AASD
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,UAAU,UAAU;IAClB,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAC5C,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;CAC7C;AASD,qEAAqE;AACrE,wBAAgB,UAAU,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAczD"}
|
package/dist/logger.js
CHANGED
|
@@ -4,15 +4,7 @@ const STATUS_COLORS = {
|
|
|
4
4
|
'4': '\x1b[33m', // yellow
|
|
5
5
|
'5': '\x1b[31m', // red
|
|
6
6
|
};
|
|
7
|
-
/**
|
|
8
|
-
* HTTP request logger — logs method, path, status, and duration.
|
|
9
|
-
*
|
|
10
|
-
* ```ts
|
|
11
|
-
* import { httpLogger } from '@fougere/http'
|
|
12
|
-
*
|
|
13
|
-
* router.use(httpLogger(logger))
|
|
14
|
-
* ```
|
|
15
|
-
*/
|
|
7
|
+
/** HTTP request logger — logs method, path, status, and duration. */
|
|
16
8
|
export function httpLogger(logger) {
|
|
17
9
|
return async (ctx, next) => {
|
|
18
10
|
const start = performance.now();
|
package/dist/logger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAUA,MAAM,aAAa,GAA2B;IAC5C,GAAG,EAAE,UAAU,EAAE,QAAQ;IACzB,GAAG,EAAE,UAAU,EAAE,OAAO;IACxB,GAAG,EAAE,UAAU,EAAE,SAAS;IAC1B,GAAG,EAAE,UAAU,EAAE,MAAM;CACxB,CAAC;AAEF
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAUA,MAAM,aAAa,GAA2B;IAC5C,GAAG,EAAE,UAAU,EAAE,QAAQ;IACzB,GAAG,EAAE,UAAU,EAAE,OAAO;IACxB,GAAG,EAAE,UAAU,EAAE,SAAS;IAC1B,GAAG,EAAE,UAAU,EAAE,MAAM;CACxB,CAAC;AAEF,qEAAqE;AACrE,MAAM,UAAU,UAAU,CAAC,MAAkB;IAC3C,OAAO,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QACzB,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;QAChC,MAAM,MAAM,GAAG,MAAM,IAAI,EAAE,CAAC;QAC5B,MAAM,EAAE,GAAG,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QAElD,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QACpC,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAC7B,MAAM,GAAG,GAAG,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC;QAE5C,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,MAAM,IAAI,GAAG,CAAC,IAAI,IAAI,MAAM,IAAI,EAAE,IAAI,CAAC,CAAC;QAEvD,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/router.d.ts
CHANGED
|
@@ -1,23 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fougere/http — framework-agnostic HTTP router interface.
|
|
3
|
-
*
|
|
4
|
-
* Adapters (Hono, Fastify, etc.) implement HttpRouter.
|
|
5
|
-
* Consumers (schema-rest, schema-graphql) program against it.
|
|
6
|
-
*/
|
|
1
|
+
/** @fougere/http — framework-agnostic HTTP router interface. */
|
|
7
2
|
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
8
3
|
export interface RequestContext {
|
|
9
|
-
/**
|
|
10
|
-
* The request as a Web Standard `Request`.
|
|
11
|
-
*
|
|
12
|
-
* Built on FIRST ACCESS. Every adapter used to build one eagerly, and no consumer
|
|
13
|
-
* in this repo reads it — measured, zero call sites outside the adapters and their
|
|
14
|
-
* tests, while the construction cost a fifth of the port's throughput on the engines
|
|
15
|
-
* that have no `Request` of their own (express, fastify). Hono hands over the one it
|
|
16
|
-
* already has, so nothing is deferred there.
|
|
17
|
-
*
|
|
18
|
-
* The fields beside it — `method`, `path`, `params`, `query`, `body` — are what the
|
|
19
|
-
* projections read, and they are not derived from this one.
|
|
20
|
-
*/
|
|
4
|
+
/** The request as a Web Standard `Request`. */
|
|
21
5
|
readonly request: Request;
|
|
22
6
|
method: HttpMethod;
|
|
23
7
|
path: string;
|
|
@@ -40,20 +24,7 @@ export declare class MalformedJsonError extends Error {
|
|
|
40
24
|
}
|
|
41
25
|
export type Handler = (ctx: RequestContext) => Promise<ResponseResult>;
|
|
42
26
|
export type Next = () => Promise<ResponseResult>;
|
|
43
|
-
/**
|
|
44
|
-
* What `next()` answers when the host framework — not us — owns the chain.
|
|
45
|
-
*
|
|
46
|
-
* Express and Fastify build their own middleware chain here, so a middleware's return IS
|
|
47
|
-
* the response and there is nothing to distinguish. Hono owns its chain, so its adapter has
|
|
48
|
-
* to tell "the middleware answered" from "the middleware delegated", and it used
|
|
49
|
-
* `data === null` for the second. `null` is a legal body — `{ status: 403, data: null }` is
|
|
50
|
-
* the ordinary spelling of a deny — so a middleware that REFUSED with no body was read as
|
|
51
|
-
* having delegated: it was silently bypassed on Hono and honoured on Fastify. One contract,
|
|
52
|
-
* two verdicts, on a value inside the value space.
|
|
53
|
-
*
|
|
54
|
-
* A symbol cannot be produced by accident, and no middleware author ever writes it: only an
|
|
55
|
-
* adapter that does not own its chain returns it from the `next` it hands out.
|
|
56
|
-
*/
|
|
27
|
+
/** What `next()` answers when the host framework — not us — owns the chain. */
|
|
57
28
|
export declare const PASSTHROUGH: unique symbol;
|
|
58
29
|
export type Middleware = (ctx: RequestContext, next: Next) => Promise<ResponseResult>;
|
|
59
30
|
export interface HttpRouter {
|
|
@@ -64,13 +35,7 @@ export interface HttpRouter {
|
|
|
64
35
|
/** Register a route handler. */
|
|
65
36
|
on(method: HttpMethod, path: string, handler: Handler): void;
|
|
66
37
|
}
|
|
67
|
-
/**
|
|
68
|
-
* The onion chain both adapters run: matching middlewares around the handler.
|
|
69
|
-
*
|
|
70
|
-
* Stated once because it was stated twice, identically, in `express.ts` and `fastify.ts` —
|
|
71
|
-
* the same package, and the same place `PASSTHROUGH` already lives. A scoped middleware
|
|
72
|
-
* matches by `startsWith`, which is what makes the two adapters agree on a mounted path.
|
|
73
|
-
*/
|
|
38
|
+
/** The onion chain both adapters run. */
|
|
74
39
|
export declare function chain(global: Middleware[], scoped: {
|
|
75
40
|
path: string;
|
|
76
41
|
mw: Middleware;
|
package/dist/router.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAEhE,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,CAAC;AAErE,MAAM,WAAW,cAAc;IAC7B,+CAA+C;IAC/C,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,MAAM,EAAE,UAAU,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,IAAI,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IAC7B,4EAA4E;IAC5E,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChC;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;IAC5C,4FAA4F;IAC5F,GAAG,CAAC,EAAE,OAAO,CAAC;CACf;AAED,4EAA4E;AAC5E,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,YAAY,OAAO,CAAC,EAAE,YAAY,EAGjC;CACF;AAED,MAAM,MAAM,OAAO,GAAG,CAAC,GAAG,EAAE,cAAc,KAAK,OAAO,CAAC,cAAc,CAAC,CAAC;AACvE,MAAM,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,cAAc,CAAC,CAAC;AACjD,+EAA+E;AAC/E,eAAO,MAAM,WAAW,EAAE,OAAO,MAA2C,CAAC;AAE7E,MAAM,MAAM,UAAU,GAAG,CAAC,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,cAAc,CAAC,CAAC;AAEtF,MAAM,WAAW,UAAU;IACzB,oCAAoC;IACpC,GAAG,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI,CAAC;IAClC,qDAAqD;IACrD,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,GAAG,IAAI,CAAC;IAChD,gCAAgC;IAChC,EAAE,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;CAC9D;AAED,yCAAyC;AACzC,wBAAgB,KAAK,CACnB,MAAM,EAAE,UAAU,EAAE,EACpB,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,UAAU,CAAA;CAAE,EAAE,EAC1C,GAAG,EAAE,cAAc,EACnB,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,cAAc,CAAC,CAWzB"}
|
package/dist/router.js
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fougere/http — framework-agnostic HTTP router interface.
|
|
3
|
-
*
|
|
4
|
-
* Adapters (Hono, Fastify, etc.) implement HttpRouter.
|
|
5
|
-
* Consumers (schema-rest, schema-graphql) program against it.
|
|
6
|
-
*/
|
|
1
|
+
/** @fougere/http — framework-agnostic HTTP router interface. */
|
|
7
2
|
/** Raised by an adapter when a request claims JSON but cannot be parsed. */
|
|
8
3
|
export class MalformedJsonError extends Error {
|
|
9
4
|
constructor(options) {
|
|
@@ -11,28 +6,9 @@ export class MalformedJsonError extends Error {
|
|
|
11
6
|
this.name = 'MalformedJsonError';
|
|
12
7
|
}
|
|
13
8
|
}
|
|
14
|
-
/**
|
|
15
|
-
* What `next()` answers when the host framework — not us — owns the chain.
|
|
16
|
-
*
|
|
17
|
-
* Express and Fastify build their own middleware chain here, so a middleware's return IS
|
|
18
|
-
* the response and there is nothing to distinguish. Hono owns its chain, so its adapter has
|
|
19
|
-
* to tell "the middleware answered" from "the middleware delegated", and it used
|
|
20
|
-
* `data === null` for the second. `null` is a legal body — `{ status: 403, data: null }` is
|
|
21
|
-
* the ordinary spelling of a deny — so a middleware that REFUSED with no body was read as
|
|
22
|
-
* having delegated: it was silently bypassed on Hono and honoured on Fastify. One contract,
|
|
23
|
-
* two verdicts, on a value inside the value space.
|
|
24
|
-
*
|
|
25
|
-
* A symbol cannot be produced by accident, and no middleware author ever writes it: only an
|
|
26
|
-
* adapter that does not own its chain returns it from the `next` it hands out.
|
|
27
|
-
*/
|
|
9
|
+
/** What `next()` answers when the host framework — not us — owns the chain. */
|
|
28
10
|
export const PASSTHROUGH = Symbol('fougere.http.passthrough');
|
|
29
|
-
/**
|
|
30
|
-
* The onion chain both adapters run: matching middlewares around the handler.
|
|
31
|
-
*
|
|
32
|
-
* Stated once because it was stated twice, identically, in `express.ts` and `fastify.ts` —
|
|
33
|
-
* the same package, and the same place `PASSTHROUGH` already lives. A scoped middleware
|
|
34
|
-
* matches by `startsWith`, which is what makes the two adapters agree on a mounted path.
|
|
35
|
-
*/
|
|
11
|
+
/** The onion chain both adapters run. */
|
|
36
12
|
export function chain(global, scoped, ctx, handler) {
|
|
37
13
|
const matching = [
|
|
38
14
|
...global,
|
package/dist/router.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.js","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"router.js","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAwBhE,4EAA4E;AAC5E,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAC3C,YAAY,OAAsB;QAChC,KAAK,CAAC,qBAAqB,EAAE,OAAO,CAAC,CAAC;QACtC,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IACnC,CAAC;CACF;AAID,+EAA+E;AAC/E,MAAM,CAAC,MAAM,WAAW,GAAkB,MAAM,CAAC,0BAA0B,CAAC,CAAC;AAa7E,yCAAyC;AACzC,MAAM,UAAU,KAAK,CACnB,MAAoB,EACpB,MAA0C,EAC1C,GAAmB,EACnB,OAAgB;IAEhB,MAAM,QAAQ,GAAG;QACf,GAAG,MAAM;QACT,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACtE,CAAC;IAEF,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,MAAM,IAAI,GAAG,GAA4B,EAAE,CACzC,KAAK,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAExE,OAAO,IAAI,EAAE,CAAC;AAChB,CAAC"}
|
package/package.json
CHANGED
package/src/express.ts
CHANGED
|
@@ -1,16 +1,4 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Express adapter — bridges an Express app to the HttpRouter interface.
|
|
3
|
-
*
|
|
4
|
-
* The one that is not Web-standard, and that is the whole substance of this file.
|
|
5
|
-
* Hono hands over `c.req.raw`, Fastify parses the body for us; Express hands a
|
|
6
|
-
* Node `IncomingMessage` and parses nothing unless the app happens to have mounted
|
|
7
|
-
* `express.json()`. So the conversion lives here — read the stream when nobody
|
|
8
|
-
* else did, and build the `Request` the interface promises.
|
|
9
|
-
*
|
|
10
|
-
* Working with or without `express.json()` is deliberate: an adapter that only
|
|
11
|
-
* works when the host app is configured a particular way is a footgun, and this
|
|
12
|
-
* one is meant to be dropped into an app that already exists.
|
|
13
|
-
*/
|
|
1
|
+
/** Express adapter — bridges an Express app to the HttpRouter interface. */
|
|
14
2
|
import { MalformedJsonError, chain, type HttpRouter, type HttpMethod, type RequestContext, type ResponseResult, type Middleware, type Handler } from './router.js';
|
|
15
3
|
|
|
16
4
|
interface ExpressLike {
|
|
@@ -56,15 +44,7 @@ export function readRawBody(req: any): Promise<string> {
|
|
|
56
44
|
});
|
|
57
45
|
}
|
|
58
46
|
|
|
59
|
-
/**
|
|
60
|
-
* The JSON body of an Express request, whoever parsed it.
|
|
61
|
-
*
|
|
62
|
-
* Exported because two consumers need the same Express fact: this adapter, and the
|
|
63
|
-
* middlewares in `@fougere/app/express`. `express.json()` may or may not have run —
|
|
64
|
-
* an adapter that only works when the host app is configured a particular way is a
|
|
65
|
-
* footgun — so this trusts `req.body` when it is there and drains the stream when it
|
|
66
|
-
* is not. Parsed once per request: a drained stream answers empty the second time.
|
|
67
|
-
*/
|
|
47
|
+
/** The JSON body of an Express request, whoever parsed it. */
|
|
68
48
|
export function readExpressBody(req: any): Promise<unknown> {
|
|
69
49
|
if (req.__fougereBody) return req.__fougereBody;
|
|
70
50
|
|
|
@@ -138,17 +118,7 @@ function sendResponse(res: any, result: ResponseResult): void {
|
|
|
138
118
|
else res.json(result.data);
|
|
139
119
|
}
|
|
140
120
|
|
|
141
|
-
/**
|
|
142
|
-
* Create an HttpRouter backed by an Express app.
|
|
143
|
-
*
|
|
144
|
-
* ```ts
|
|
145
|
-
* import express from 'express'
|
|
146
|
-
* import { createExpressRouter } from '@fougere/http'
|
|
147
|
-
*
|
|
148
|
-
* const app = express()
|
|
149
|
-
* const router = createExpressRouter(app)
|
|
150
|
-
* ```
|
|
151
|
-
*/
|
|
121
|
+
/** Create an HttpRouter backed by an Express app. */
|
|
152
122
|
export function createExpressRouter(app: ExpressLike): HttpRouter {
|
|
153
123
|
const globalMiddlewares: Middleware[] = [];
|
|
154
124
|
const scopedMiddlewares: { path: string; mw: Middleware }[] = [];
|
package/src/fastify.ts
CHANGED
|
@@ -63,17 +63,7 @@ function sendResponse(reply: any, result: ResponseResult): void {
|
|
|
63
63
|
reply.status(result.status).send(result.data);
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
/**
|
|
67
|
-
* Create an HttpRouter backed by a Fastify server.
|
|
68
|
-
*
|
|
69
|
-
* ```ts
|
|
70
|
-
* import Fastify from 'fastify'
|
|
71
|
-
* import { createFastifyRouter } from '@fougere/http'
|
|
72
|
-
*
|
|
73
|
-
* const fastify = Fastify()
|
|
74
|
-
* const router = createFastifyRouter(fastify)
|
|
75
|
-
* ```
|
|
76
|
-
*/
|
|
66
|
+
/** Create an HttpRouter backed by a Fastify server. */
|
|
77
67
|
export function createFastifyRouter(server: FastifyLike): HttpRouter {
|
|
78
68
|
const globalMiddlewares: Middleware[] = [];
|
|
79
69
|
const scopedMiddlewares: { path: string; mw: Middleware }[] = [];
|
package/src/hono.ts
CHANGED
|
@@ -72,17 +72,7 @@ function malformedJsonResponse(c: any): Response {
|
|
|
72
72
|
return sendResponse(c, { status: 400, data: { code: 'BAD_REQUEST', message: 'Malformed JSON body' } });
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
/**
|
|
76
|
-
* Create an HttpRouter backed by a Hono app.
|
|
77
|
-
*
|
|
78
|
-
* ```ts
|
|
79
|
-
* import { Hono } from 'hono'
|
|
80
|
-
* import { createHonoRouter } from '@fougere/http'
|
|
81
|
-
*
|
|
82
|
-
* const hono = new Hono()
|
|
83
|
-
* const router = createHonoRouter(hono)
|
|
84
|
-
* ```
|
|
85
|
-
*/
|
|
75
|
+
/** Create an HttpRouter backed by a Hono app. */
|
|
86
76
|
export function createHonoRouter(app: HonoLike): HttpRouter {
|
|
87
77
|
return {
|
|
88
78
|
use(...args: [Middleware] | [string, Middleware]): void {
|
package/src/logger.ts
CHANGED
|
@@ -15,15 +15,7 @@ const STATUS_COLORS: Record<string, string> = {
|
|
|
15
15
|
'5': '\x1b[31m', // red
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
/**
|
|
19
|
-
* HTTP request logger — logs method, path, status, and duration.
|
|
20
|
-
*
|
|
21
|
-
* ```ts
|
|
22
|
-
* import { httpLogger } from '@fougere/http'
|
|
23
|
-
*
|
|
24
|
-
* router.use(httpLogger(logger))
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
18
|
+
/** HTTP request logger — logs method, path, status, and duration. */
|
|
27
19
|
export function httpLogger(logger: LoggerLike): Middleware {
|
|
28
20
|
return async (ctx, next) => {
|
|
29
21
|
const start = performance.now();
|
package/src/router.ts
CHANGED
|
@@ -1,25 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fougere/http — framework-agnostic HTTP router interface.
|
|
3
|
-
*
|
|
4
|
-
* Adapters (Hono, Fastify, etc.) implement HttpRouter.
|
|
5
|
-
* Consumers (schema-rest, schema-graphql) program against it.
|
|
6
|
-
*/
|
|
1
|
+
/** @fougere/http — framework-agnostic HTTP router interface. */
|
|
7
2
|
|
|
8
3
|
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
9
4
|
|
|
10
5
|
export interface RequestContext {
|
|
11
|
-
/**
|
|
12
|
-
* The request as a Web Standard `Request`.
|
|
13
|
-
*
|
|
14
|
-
* Built on FIRST ACCESS. Every adapter used to build one eagerly, and no consumer
|
|
15
|
-
* in this repo reads it — measured, zero call sites outside the adapters and their
|
|
16
|
-
* tests, while the construction cost a fifth of the port's throughput on the engines
|
|
17
|
-
* that have no `Request` of their own (express, fastify). Hono hands over the one it
|
|
18
|
-
* already has, so nothing is deferred there.
|
|
19
|
-
*
|
|
20
|
-
* The fields beside it — `method`, `path`, `params`, `query`, `body` — are what the
|
|
21
|
-
* projections read, and they are not derived from this one.
|
|
22
|
-
*/
|
|
6
|
+
/** The request as a Web Standard `Request`. */
|
|
23
7
|
readonly request: Request;
|
|
24
8
|
method: HttpMethod;
|
|
25
9
|
path: string;
|
|
@@ -48,20 +32,7 @@ export class MalformedJsonError extends Error {
|
|
|
48
32
|
|
|
49
33
|
export type Handler = (ctx: RequestContext) => Promise<ResponseResult>;
|
|
50
34
|
export type Next = () => Promise<ResponseResult>;
|
|
51
|
-
/**
|
|
52
|
-
* What `next()` answers when the host framework — not us — owns the chain.
|
|
53
|
-
*
|
|
54
|
-
* Express and Fastify build their own middleware chain here, so a middleware's return IS
|
|
55
|
-
* the response and there is nothing to distinguish. Hono owns its chain, so its adapter has
|
|
56
|
-
* to tell "the middleware answered" from "the middleware delegated", and it used
|
|
57
|
-
* `data === null` for the second. `null` is a legal body — `{ status: 403, data: null }` is
|
|
58
|
-
* the ordinary spelling of a deny — so a middleware that REFUSED with no body was read as
|
|
59
|
-
* having delegated: it was silently bypassed on Hono and honoured on Fastify. One contract,
|
|
60
|
-
* two verdicts, on a value inside the value space.
|
|
61
|
-
*
|
|
62
|
-
* A symbol cannot be produced by accident, and no middleware author ever writes it: only an
|
|
63
|
-
* adapter that does not own its chain returns it from the `next` it hands out.
|
|
64
|
-
*/
|
|
35
|
+
/** What `next()` answers when the host framework — not us — owns the chain. */
|
|
65
36
|
export const PASSTHROUGH: unique symbol = Symbol('fougere.http.passthrough');
|
|
66
37
|
|
|
67
38
|
export type Middleware = (ctx: RequestContext, next: Next) => Promise<ResponseResult>;
|
|
@@ -75,13 +46,7 @@ export interface HttpRouter {
|
|
|
75
46
|
on(method: HttpMethod, path: string, handler: Handler): void;
|
|
76
47
|
}
|
|
77
48
|
|
|
78
|
-
/**
|
|
79
|
-
* The onion chain both adapters run: matching middlewares around the handler.
|
|
80
|
-
*
|
|
81
|
-
* Stated once because it was stated twice, identically, in `express.ts` and `fastify.ts` —
|
|
82
|
-
* the same package, and the same place `PASSTHROUGH` already lives. A scoped middleware
|
|
83
|
-
* matches by `startsWith`, which is what makes the two adapters agree on a mounted path.
|
|
84
|
-
*/
|
|
49
|
+
/** The onion chain both adapters run. */
|
|
85
50
|
export function chain(
|
|
86
51
|
global: Middleware[],
|
|
87
52
|
scoped: { path: string; mw: Middleware }[],
|