From 88b41798d6c3d7b25f9d0d4152f7f58cef5026f1 Mon Sep 17 00:00:00 2001 From: Danijel Martinek Date: Wed, 13 May 2026 17:51:16 +0000 Subject: [PATCH] refactor(auth): migrate use-case binders to wireUseCase Replace inline withSpan + withCapture blocks for signIn, signUp, and signOut use cases in both bind-production.ts and bind-dev-seed.ts with wireUseCase calls. Removes 27 lines of boilerplate per binder file. Co-Authored-By: Claude Sonnet 4.6 --- coverage/summary.json | 20 +++--- packages/auth/src/di/bind-dev-seed.ts | 75 ++++++++++----------- packages/auth/src/di/bind-production.ts | 88 ++++++++++--------------- 3 files changed, 81 insertions(+), 102 deletions(-) diff --git a/coverage/summary.json b/coverage/summary.json index 7d87bf7..6094ac2 100644 --- a/coverage/summary.json +++ b/coverage/summary.json @@ -1,14 +1,14 @@ { - "generatedAt": "2026-05-13T14:38:41.601Z", - "commit": "6428f10", + "generatedAt": "2026-05-13T17:51:01.137Z", + "commit": "e08e0a1", "repo": { - "statements": 95.87, + "statements": 95.86, "branches": 88.91, "functions": 100, - "lines": 95.87, + "lines": 95.86, "counts": { - "lf": 3123, - "lh": 2994, + "lf": 3117, + "lh": 2988, "brf": 487, "brh": 433, "fnf": 142, @@ -17,13 +17,13 @@ }, "byPackage": { "@repo/auth": { - "statements": 93.85, + "statements": 93.81, "branches": 90.82, "functions": 100, - "lines": 93.85, + "lines": 93.81, "counts": { - "lf": 797, - "lh": 748, + "lf": 791, + "lh": 742, "brf": 98, "brh": 89, "fnf": 44, diff --git a/packages/auth/src/di/bind-dev-seed.ts b/packages/auth/src/di/bind-dev-seed.ts index b5ac201..b0c5386 100644 --- a/packages/auth/src/di/bind-dev-seed.ts +++ b/packages/auth/src/di/bind-dev-seed.ts @@ -6,7 +6,10 @@ import { type ILogger, } from "@repo/core-shared/instrumentation"; import type { BindContext } from "@repo/core-shared/di"; -import { assertFeatureConformance } from "@repo/core-shared/conformance"; +import { + assertFeatureConformance, + wireUseCase, +} from "@repo/core-shared/conformance"; import { authManifest } from "../feature.manifest.js"; import { authContainer } from "./container.js"; import { AUTH_SYMBOLS } from "./symbols.js"; @@ -69,55 +72,49 @@ export async function bindDevSeedAuth(ctx: BindContext): Promise { AUTH_SYMBOLS.IAuthenticationService, ); - // Wrap use cases + controllers identically to bind-production - const wrappedSignIn = withSpan( + // Use cases + const wrappedSignIn = wireUseCase({ + container: authContainer, + symbol: AUTH_SYMBOLS.ISignInUseCase, + factory: signInUseCase, + deps: [repo, authService], + feature: "auth", + layer: "use-case", + name: "signIn", tracer, - { name: "auth.signIn", op: "use-case" }, - withCapture( - logger, - { feature: "auth", layer: "use-case", name: "auth.signIn" }, - signInUseCase(repo, authService), - ), - ); - const wrappedSignUp = withSpan( + logger, + }); + const wrappedSignUp = wireUseCase({ + container: authContainer, + symbol: AUTH_SYMBOLS.ISignUpUseCase, + factory: signUpUseCase, + deps: [repo, authService, bus], + feature: "auth", + layer: "use-case", + name: "signUp", tracer, - { name: "auth.signUp", op: "use-case" }, - withCapture( - logger, - { feature: "auth", layer: "use-case", name: "auth.signUp" }, - signUpUseCase(repo, authService, bus), - ), - ); - const wrappedSignOut = withSpan( + logger, + }); + const wrappedSignOut = wireUseCase({ + container: authContainer, + symbol: AUTH_SYMBOLS.ISignOutUseCase, + factory: signOutUseCase, + deps: [authService], + feature: "auth", + layer: "use-case", + name: "signOut", tracer, - { name: "auth.signOut", op: "use-case" }, - withCapture( - logger, - { feature: "auth", layer: "use-case", name: "auth.signOut" }, - signOutUseCase(authService), - ), - ); + logger, + }); + // Controllers for (const sym of [ - AUTH_SYMBOLS.ISignInUseCase, - AUTH_SYMBOLS.ISignUpUseCase, - AUTH_SYMBOLS.ISignOutUseCase, AUTH_SYMBOLS.ISignInController, AUTH_SYMBOLS.ISignUpController, AUTH_SYMBOLS.ISignOutController, ]) { if (authContainer.isBound(sym)) authContainer.unbind(sym); } - authContainer - .bind(AUTH_SYMBOLS.ISignInUseCase) - .toConstantValue(wrappedSignIn); - authContainer - .bind(AUTH_SYMBOLS.ISignUpUseCase) - .toConstantValue(wrappedSignUp); - authContainer - .bind(AUTH_SYMBOLS.ISignOutUseCase) - .toConstantValue(wrappedSignOut); - authContainer .bind(AUTH_SYMBOLS.ISignInController) .toConstantValue( diff --git a/packages/auth/src/di/bind-production.ts b/packages/auth/src/di/bind-production.ts index 96db76a..bca0bd2 100644 --- a/packages/auth/src/di/bind-production.ts +++ b/packages/auth/src/di/bind-production.ts @@ -6,14 +6,11 @@ import { type ILogger, } from "@repo/core-shared/instrumentation"; import type { BindProductionContext } from "@repo/core-shared/di"; -import { assertFeatureConformance } from "@repo/core-shared/conformance"; -import type { ProductionUseCase } from "@repo/core-shared/conformance"; +import { + assertFeatureConformance, + wireUseCase, +} from "@repo/core-shared/conformance"; import { authManifest } from "../feature.manifest"; -import type { AuthManifest } from "../feature.manifest"; -import type { - SignInInput, - SignInOutput, -} from "../application/use-cases/sign-in.use-case"; import { authContainer } from "./container"; import { AUTH_SYMBOLS } from "./symbols"; import { UsersRepository } from "../infrastructure/repositories/users.repository"; @@ -67,55 +64,40 @@ export function bindProductionAuth(ctx: BindProductionContext): void { .bind(AUTH_SYMBOLS.IAuthenticationService) .toConstantValue(authService); - // Use cases — wrapped with span + capture at bind time - const wrappedSignIn: ProductionUseCase< - SignInInput, - SignInOutput, - AuthManifest["useCases"]["signIn"] - > = withSpan( + // Use cases + const wrappedSignIn = wireUseCase({ + container: authContainer, + symbol: AUTH_SYMBOLS.ISignInUseCase, + factory: signInUseCase, + deps: [repo, authService], + feature: "auth", + layer: "use-case", + name: "signIn", tracer, - { name: "auth.signIn", op: "use-case" }, - withCapture( - logger, - { feature: "auth", layer: "use-case", name: "auth.signIn" }, - signInUseCase(repo, authService), - ), - ); - const wrappedSignUp = withSpan( + logger, + }); + const wrappedSignUp = wireUseCase({ + container: authContainer, + symbol: AUTH_SYMBOLS.ISignUpUseCase, + factory: signUpUseCase, + deps: [repo, authService, bus], + feature: "auth", + layer: "use-case", + name: "signUp", tracer, - { name: "auth.signUp", op: "use-case" }, - withCapture( - logger, - { feature: "auth", layer: "use-case", name: "auth.signUp" }, - signUpUseCase(repo, authService, bus), - ), - ); - const wrappedSignOut = withSpan( + logger, + }); + const wrappedSignOut = wireUseCase({ + container: authContainer, + symbol: AUTH_SYMBOLS.ISignOutUseCase, + factory: signOutUseCase, + deps: [authService], + feature: "auth", + layer: "use-case", + name: "signOut", tracer, - { name: "auth.signOut", op: "use-case" }, - withCapture( - logger, - { feature: "auth", layer: "use-case", name: "auth.signOut" }, - signOutUseCase(authService), - ), - ); - - for (const sym of [ - AUTH_SYMBOLS.ISignInUseCase, - AUTH_SYMBOLS.ISignUpUseCase, - AUTH_SYMBOLS.ISignOutUseCase, - ]) { - if (authContainer.isBound(sym)) authContainer.unbind(sym); - } - authContainer - .bind(AUTH_SYMBOLS.ISignInUseCase) - .toConstantValue(wrappedSignIn); - authContainer - .bind(AUTH_SYMBOLS.ISignUpUseCase) - .toConstantValue(wrappedSignUp); - authContainer - .bind(AUTH_SYMBOLS.ISignOutUseCase) - .toConstantValue(wrappedSignOut); + logger, + }); // Controllers — wrapped with span at bind time for (const sym of [