@bgord/bun 1.12.9 → 1.12.10
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/timing-hono.middleware.d.ts.map +1 -1
- package/dist/timing-hono.middleware.js +6 -2
- package/dist/timing-hono.middleware.js.map +1 -1
- package/dist/timing.middleware.d.ts +2 -1
- package/dist/timing.middleware.d.ts.map +1 -1
- package/dist/timing.middleware.js +4 -1
- package/dist/timing.middleware.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/timing-hono.middleware.ts +7 -2
- package/src/timing.middleware.ts +6 -1
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createMiddleware } from "hono/factory";
|
|
2
2
|
import type { ClockPort } from "./clock.port";
|
|
3
3
|
import type { MiddlewareHonoPort } from "./middleware-hono.port";
|
|
4
|
+
import { RequestContextHonoAdapter } from "./request-context-hono.adapter";
|
|
4
5
|
import { TimingMiddleware } from "./timing.middleware";
|
|
5
6
|
|
|
6
7
|
type Dependencies = { Clock: ClockPort };
|
|
@@ -14,9 +15,13 @@ export class TimingHonoMiddleware implements MiddlewareHonoPort {
|
|
|
14
15
|
|
|
15
16
|
handle() {
|
|
16
17
|
return createMiddleware(async (c, next) => {
|
|
17
|
-
const
|
|
18
|
+
const context = new RequestContextHonoAdapter(c);
|
|
18
19
|
|
|
19
|
-
|
|
20
|
+
const timing = await this.middleware.measure(context, () => next());
|
|
21
|
+
|
|
22
|
+
if (!timing) return next();
|
|
23
|
+
|
|
24
|
+
c.header(TimingMiddleware.HEADER_NAME, timing);
|
|
20
25
|
});
|
|
21
26
|
}
|
|
22
27
|
}
|
package/src/timing.middleware.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ClockPort } from "./clock.port";
|
|
2
|
+
import type { RequestContext } from "./request-context.port";
|
|
2
3
|
import { Stopwatch } from "./stopwatch.service";
|
|
3
4
|
|
|
4
5
|
type Dependencies = { Clock: ClockPort };
|
|
@@ -8,7 +9,11 @@ export class TimingMiddleware {
|
|
|
8
9
|
|
|
9
10
|
constructor(private readonly deps: Dependencies) {}
|
|
10
11
|
|
|
11
|
-
async measure(action: () => void | Promise<void>): Promise<string> {
|
|
12
|
+
async measure(context: RequestContext, action: () => void | Promise<void>): Promise<string | null> {
|
|
13
|
+
const header = context.request.header("accept");
|
|
14
|
+
|
|
15
|
+
if (header === "text/event-stream") return null;
|
|
16
|
+
|
|
12
17
|
const stopwatch = new Stopwatch(this.deps);
|
|
13
18
|
|
|
14
19
|
await action();
|