|
1 | 1 | import { z } from "zod" |
2 | 2 | import { baseLogSchema } from "./schemas" |
3 | | -import { catchUncaughtAction, catchUncaughtRoute } from "./request-utils" |
| 3 | +import { |
| 4 | + catchUncaughtAction, |
| 5 | + catchUncaughtRoute, |
| 6 | + json, |
| 7 | + redirect, |
| 8 | + response, |
| 9 | +} from "./request-utils" |
4 | 10 | import { buildJsonLog, buildTextLog } from "./utils" |
5 | 11 |
|
6 | 12 | export type FlytrapLogsOptions = { |
@@ -71,7 +77,7 @@ export function createFlytrapLogger<T>({ |
71 | 77 | method: "GET", |
72 | 78 | } satisfies z.infer<typeof baseLogSchema> |
73 | 79 |
|
74 | | - let logs: Array<Partial<Log>> = [defaultLog as Log] |
| 80 | + const logs: Array<Partial<Log>> = [defaultLog as Log] |
75 | 81 |
|
76 | 82 | // Function defintions |
77 | 83 | function getContext() { |
@@ -125,12 +131,27 @@ export function createFlytrapLogger<T>({ |
125 | 131 | fn: T, |
126 | 132 | options?: Partial<z.infer<typeof baseLogSchema>> |
127 | 133 | ) { |
| 134 | + // @ts-expect-error |
128 | 135 | return catchUncaughtAction(fn, addContext, flush, options) |
129 | 136 | }, |
130 | 137 | catchUncaughtRoute<T extends { params: Record<string, unknown> }>( |
131 | | - fn: (request: Request, context: T) => Promise<Response> | Response |
| 138 | + fn: (request: Request, context: T) => Promise<Response> | Response, |
| 139 | + options?: Partial<z.infer<typeof baseLogSchema>> |
132 | 140 | ) { |
133 | | - return catchUncaughtRoute(fn, addContext, flush) |
| 141 | + // @ts-expect-error |
| 142 | + return catchUncaughtRoute(fn, addContext, flush, options) |
| 143 | + }, |
| 144 | + response(body: BodyInit, opts: ResponseInit = {}) { |
| 145 | + // @ts-expect-error |
| 146 | + return response(body, opts, addContext) |
| 147 | + }, |
| 148 | + json(data: any, opts: ResponseInit = {}) { |
| 149 | + // @ts-expect-error |
| 150 | + return json(data, opts, addContext) |
| 151 | + }, |
| 152 | + redirect(url: string | URL, status?: number) { |
| 153 | + // @ts-expect-error |
| 154 | + return redirect(url, status, addContext) |
134 | 155 | }, |
135 | 156 | } |
136 | 157 | } |
0 commit comments