refactor(auth): binders take BindContext arg

This commit is contained in:
2026-05-09 12:39:50 +02:00
parent f4942098f1
commit ab8ca08307
3 changed files with 14 additions and 28 deletions

View File

@@ -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<IUsersRepository>(
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<IUsersRepository>(
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<IUsersRepository>(
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<IUsersRepository>(
AUTH_SYMBOLS.IUsersRepository,
);

View File

@@ -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<void> {
export async function bindDevSeedAuth(ctx: BindContext): Promise<void> {
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(

View File

@@ -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(