From 7aa11b7a8abacf81dec20fff21216df35d333756 Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Sun, 27 Jul 2025 18:50:33 -0700 Subject: Pulls in pengueno from npm --- u/server/response/pengueno.ts | 59 ------------------------------------------- 1 file changed, 59 deletions(-) delete mode 100644 u/server/response/pengueno.ts (limited to 'u/server/response/pengueno.ts') diff --git a/u/server/response/pengueno.ts b/u/server/response/pengueno.ts deleted file mode 100644 index 5a953db..0000000 --- a/u/server/response/pengueno.ts +++ /dev/null @@ -1,59 +0,0 @@ -import { - BaseResponse, - Body, - HttpStatusCodes, - ITraceable, - Metric, - Optional, - PenguenoRequest, - ResponseOpts, - ServerTrace, -} from '@emprespresso/pengueno'; - -const getHeaders = (req: PenguenoRequest, extraHeaders: Record) => { - const optHeaders = { - ...req.getResponseHeaders(), - ...extraHeaders, - }; - optHeaders['Content-Type'] = (optHeaders['Content-Type'] ?? 'text/plain') + '; charset=utf-8'; - return optHeaders; -}; - -const ResponseCodeMetrics = [0, 1, 2, 3, 4, 5].map((x) => Metric.fromName(`response.${x}xx`).asResult()); -export const getResponseMetrics = (status: number, elapsedMs?: number) => { - const index = Math.floor(status / 100); - return ResponseCodeMetrics.flatMap((metric, i) => - Optional.from(i) - .filter((i) => i === index) - .map(() => [metric.count.withValue(1.0)]) - .flatMap((metricValues) => - Optional.from(elapsedMs) - .map((ms) => metricValues.concat(metric.time.withValue(ms))) - .orSome(() => metricValues), - ) - .orSome(() => [metric.count.withValue(0.0)]) - .get(), - ); -}; - -export class PenguenoResponse implements BaseResponse { - public readonly statusText: string; - public readonly status: number; - public readonly headers: Record; - - constructor( - req: ITraceable, - private readonly _body: Body, - opts: ResponseOpts, - ) { - this.headers = getHeaders(req.get(), opts?.headers ?? {}); - this.status = opts.status; - this.statusText = opts.statusText ?? HttpStatusCodes[this.status]!; - - req.trace.trace(getResponseMetrics(opts.status, req.get().elapsedTimeMs())); - } - - public body() { - return this._body; - } -} -- cgit v1.2.3-70-g09d2