From a1fbd16d8376cb4ab6422b2c7caabecb1726d664 Mon Sep 17 00:00:00 2001 From: Danijel Martinek Date: Tue, 12 May 2026 21:32:42 +0200 Subject: [PATCH] feat(core-shared/instrumentation): withCapture returns Captured --- .../src/instrumentation/with-capture.test.ts | 12 +++++++++++- .../core-shared/src/instrumentation/with-capture.ts | 6 ++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/core-shared/src/instrumentation/with-capture.test.ts b/packages/core-shared/src/instrumentation/with-capture.test.ts index 8b056d3..28b4803 100644 --- a/packages/core-shared/src/instrumentation/with-capture.test.ts +++ b/packages/core-shared/src/instrumentation/with-capture.test.ts @@ -1,7 +1,8 @@ -import { describe, it, expect, vi } from "vitest"; +import { describe, it, expect, expectTypeOf, vi } from "vitest"; import { withCapture } from "@/instrumentation/with-capture"; import type { ILogger } from "@/instrumentation/logger.interface"; import { isReported } from "@/instrumentation/reported-flag"; +import type { Captured } from "@/conformance/brands"; function makeLogger(): ILogger & { captureException: ReturnType } { return { @@ -60,3 +61,12 @@ describe("withCapture", () => { }); }); }); + +describe("withCapture — brand", () => { + it("returns a Captured", () => { + const logger = makeLogger(); + const fn = async (a: number) => a + 1; + const wrapped = withCapture(logger, { layer: "use-case" }, fn); + expectTypeOf(wrapped).toMatchTypeOf>(); + }); +}); diff --git a/packages/core-shared/src/instrumentation/with-capture.ts b/packages/core-shared/src/instrumentation/with-capture.ts index f9fbeb9..ed17420 100644 --- a/packages/core-shared/src/instrumentation/with-capture.ts +++ b/packages/core-shared/src/instrumentation/with-capture.ts @@ -1,4 +1,5 @@ import type { ILogger } from "./logger.interface"; +import type { Captured } from "../conformance/brands"; import { isReported, markReported } from "./reported-flag"; /** @@ -25,8 +26,8 @@ export function withCapture( logger: ILogger, tags: Record, fn: (...args: Args) => Promise, -): (...args: Args) => Promise { - return async (...args) => { +): Captured<(...args: Args) => Promise> { + const wrapped: (...args: Args) => Promise = async (...args) => { try { return await fn(...args); } catch (err) { @@ -37,4 +38,5 @@ export function withCapture( throw err; } }; + return wrapped as Captured<(...args: Args) => Promise>; }