From ab8ca083073efab90c83f32667437557c9274896 Mon Sep 17 00:00:00 2001 From: Danijel Martinek Date: Sat, 9 May 2026 12:39:50 +0200 Subject: [PATCH] refactor(auth): binders take BindContext arg --- packages/auth/src/di/bind-dev-seed.test.ts | 8 ++++---- packages/auth/src/di/bind-dev-seed.ts | 16 +++++----------- packages/auth/src/di/bind-production.ts | 18 +++++------------- 3 files changed, 14 insertions(+), 28 deletions(-) diff --git a/packages/auth/src/di/bind-dev-seed.test.ts b/packages/auth/src/di/bind-dev-seed.test.ts index 28ee4dc..52e036f 100644 --- a/packages/auth/src/di/bind-dev-seed.test.ts +++ b/packages/auth/src/di/bind-dev-seed.test.ts @@ -33,7 +33,7 @@ describe("bindDevSeedAuth", () => { }); it("populates the repository with the dev users", async () => { - await bindDevSeedAuth(noop.tracer, noop.logger, new RecordingEventBus(), new RecordingJobQueue(), new RecordingRealtimeBroadcaster(), new RealtimeHandlerRegistry()); + await bindDevSeedAuth({ ...noop, bus: new RecordingEventBus(), queue: new RecordingJobQueue(), realtime: new RecordingRealtimeBroadcaster(), realtimeRegistry: new RealtimeHandlerRegistry() }); const repo = authContainer.get( AUTH_SYMBOLS.IUsersRepository, @@ -46,7 +46,7 @@ describe("bindDevSeedAuth", () => { }); it("seeds alice reachable by username", async () => { - await bindDevSeedAuth(noop.tracer, noop.logger, new RecordingEventBus(), new RecordingJobQueue(), new RecordingRealtimeBroadcaster(), new RealtimeHandlerRegistry()); + await bindDevSeedAuth({ ...noop, bus: new RecordingEventBus(), queue: new RecordingJobQueue(), realtime: new RecordingRealtimeBroadcaster(), realtimeRegistry: new RealtimeHandlerRegistry() }); const repo = authContainer.get( AUTH_SYMBOLS.IUsersRepository, @@ -59,13 +59,13 @@ describe("bindDevSeedAuth", () => { }); it("is idempotent — calling twice rebuilds a fresh populated repo", async () => { - await bindDevSeedAuth(noop.tracer, noop.logger, new RecordingEventBus(), new RecordingJobQueue(), new RecordingRealtimeBroadcaster(), new RealtimeHandlerRegistry()); + await bindDevSeedAuth({ ...noop, bus: new RecordingEventBus(), queue: new RecordingJobQueue(), realtime: new RecordingRealtimeBroadcaster(), realtimeRegistry: new RealtimeHandlerRegistry() }); const before = authContainer.get( AUTH_SYMBOLS.IUsersRepository, ); const beforeAlice = await before.getUserByUsername("alice"); - await bindDevSeedAuth(noop.tracer, noop.logger, new RecordingEventBus(), new RecordingJobQueue(), new RecordingRealtimeBroadcaster(), new RealtimeHandlerRegistry()); + await bindDevSeedAuth({ ...noop, bus: new RecordingEventBus(), queue: new RecordingJobQueue(), realtime: new RecordingRealtimeBroadcaster(), realtimeRegistry: new RealtimeHandlerRegistry() }); const after = authContainer.get( AUTH_SYMBOLS.IUsersRepository, ); diff --git a/packages/auth/src/di/bind-dev-seed.ts b/packages/auth/src/di/bind-dev-seed.ts index caa083f..3bbacb8 100644 --- a/packages/auth/src/di/bind-dev-seed.ts +++ b/packages/auth/src/di/bind-dev-seed.ts @@ -5,9 +5,8 @@ import { type ITracer, type ILogger, } from "@repo/core-shared/instrumentation"; +import type { BindContext } from "@repo/core-shared/di"; import type { IEventBus } from "@repo/core-events"; -import type { IRealtimeBroadcaster, IRealtimeHandlerRegistry } from "@repo/core-realtime"; -import type { IJobQueue } from "@repo/core-shared/jobs"; import { authContainer } from "./container.js"; import { AUTH_SYMBOLS } from "./symbols.js"; import { MockUsersRepository } from "../infrastructure/repositories/users.repository.mock.js"; @@ -34,14 +33,9 @@ import type { IAuthenticationService } from "../application/services/authenticat * Idempotent: safe to call multiple times; each call rebuilds a fresh * populated repo and rebinds the symbol. */ -export async function bindDevSeedAuth( - tracer: ITracer, - logger: ILogger, - bus: IEventBus, - queue: IJobQueue, - realtime: IRealtimeBroadcaster, - realtimeRegistry: IRealtimeHandlerRegistry, -): Promise { +export async function bindDevSeedAuth(ctx: BindContext): Promise { + const { tracer, logger, bus, queue, realtime, realtimeRegistry } = ctx; + // Bind shared instrumentation into feature container if (authContainer.isBound(INSTRUMENTATION_SYMBOLS.TRACER)) { authContainer.unbind(INSTRUMENTATION_SYMBOLS.TRACER); @@ -84,7 +78,7 @@ export async function bindDevSeedAuth( withCapture( logger, { feature: "auth", layer: "use-case", name: "auth.signUp" }, - signUpUseCase(repo, authService, bus), + signUpUseCase(repo, authService, bus as IEventBus), ), ); const wrappedSignOut = withSpan( diff --git a/packages/auth/src/di/bind-production.ts b/packages/auth/src/di/bind-production.ts index 759453a..6236167 100644 --- a/packages/auth/src/di/bind-production.ts +++ b/packages/auth/src/di/bind-production.ts @@ -1,4 +1,3 @@ -import type { SanitizedConfig } from "payload"; import { withSpan, withCapture, @@ -6,9 +5,8 @@ import { type ITracer, type ILogger, } from "@repo/core-shared/instrumentation"; +import type { BindProductionContext } from "@repo/core-shared/di"; import type { IEventBus } from "@repo/core-events"; -import type { IRealtimeBroadcaster, IRealtimeHandlerRegistry } from "@repo/core-realtime"; -import type { IJobQueue } from "@repo/core-shared/jobs"; import { authContainer } from "./container"; import { AUTH_SYMBOLS } from "./symbols"; import { UsersRepository } from "../infrastructure/repositories/users.repository"; @@ -24,18 +22,12 @@ import type { IAuthenticationService } from "../application/services/authenticat let bound = false; -export function bindProductionAuth( - config: SanitizedConfig, - tracer: ITracer, - logger: ILogger, - bus: IEventBus, - queue: IJobQueue, - realtime: IRealtimeBroadcaster, - realtimeRegistry: IRealtimeHandlerRegistry, -): void { +export function bindProductionAuth(ctx: BindProductionContext): void { if (bound) return; bound = true; + const { config, tracer, logger, bus, queue, realtime, realtimeRegistry } = ctx; + // Bind shared instrumentation into feature container if (authContainer.isBound(INSTRUMENTATION_SYMBOLS.TRACER)) { authContainer.unbind(INSTRUMENTATION_SYMBOLS.TRACER); @@ -77,7 +69,7 @@ export function bindProductionAuth( withCapture( logger, { feature: "auth", layer: "use-case", name: "auth.signUp" }, - signUpUseCase(repo, authService, bus), + signUpUseCase(repo, authService, bus as IEventBus), ), ); const wrappedSignOut = withSpan(