refactor(auth): binders take BindContext arg
This commit is contained in:
@@ -33,7 +33,7 @@ describe("bindDevSeedAuth", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("populates the repository with the dev users", async () => {
|
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>(
|
const repo = authContainer.get<IUsersRepository>(
|
||||||
AUTH_SYMBOLS.IUsersRepository,
|
AUTH_SYMBOLS.IUsersRepository,
|
||||||
@@ -46,7 +46,7 @@ describe("bindDevSeedAuth", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("seeds alice reachable by username", async () => {
|
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>(
|
const repo = authContainer.get<IUsersRepository>(
|
||||||
AUTH_SYMBOLS.IUsersRepository,
|
AUTH_SYMBOLS.IUsersRepository,
|
||||||
@@ -59,13 +59,13 @@ describe("bindDevSeedAuth", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("is idempotent — calling twice rebuilds a fresh populated repo", async () => {
|
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>(
|
const before = authContainer.get<IUsersRepository>(
|
||||||
AUTH_SYMBOLS.IUsersRepository,
|
AUTH_SYMBOLS.IUsersRepository,
|
||||||
);
|
);
|
||||||
const beforeAlice = await before.getUserByUsername("alice");
|
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>(
|
const after = authContainer.get<IUsersRepository>(
|
||||||
AUTH_SYMBOLS.IUsersRepository,
|
AUTH_SYMBOLS.IUsersRepository,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -5,9 +5,8 @@ import {
|
|||||||
type ITracer,
|
type ITracer,
|
||||||
type ILogger,
|
type ILogger,
|
||||||
} from "@repo/core-shared/instrumentation";
|
} from "@repo/core-shared/instrumentation";
|
||||||
|
import type { BindContext } from "@repo/core-shared/di";
|
||||||
import type { IEventBus } from "@repo/core-events";
|
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 { authContainer } from "./container.js";
|
||||||
import { AUTH_SYMBOLS } from "./symbols.js";
|
import { AUTH_SYMBOLS } from "./symbols.js";
|
||||||
import { MockUsersRepository } from "../infrastructure/repositories/users.repository.mock.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
|
* Idempotent: safe to call multiple times; each call rebuilds a fresh
|
||||||
* populated repo and rebinds the symbol.
|
* populated repo and rebinds the symbol.
|
||||||
*/
|
*/
|
||||||
export async function bindDevSeedAuth(
|
export async function bindDevSeedAuth(ctx: BindContext): Promise<void> {
|
||||||
tracer: ITracer,
|
const { tracer, logger, bus, queue, realtime, realtimeRegistry } = ctx;
|
||||||
logger: ILogger,
|
|
||||||
bus: IEventBus,
|
|
||||||
queue: IJobQueue,
|
|
||||||
realtime: IRealtimeBroadcaster,
|
|
||||||
realtimeRegistry: IRealtimeHandlerRegistry,
|
|
||||||
): Promise<void> {
|
|
||||||
// Bind shared instrumentation into feature container
|
// Bind shared instrumentation into feature container
|
||||||
if (authContainer.isBound(INSTRUMENTATION_SYMBOLS.TRACER)) {
|
if (authContainer.isBound(INSTRUMENTATION_SYMBOLS.TRACER)) {
|
||||||
authContainer.unbind(INSTRUMENTATION_SYMBOLS.TRACER);
|
authContainer.unbind(INSTRUMENTATION_SYMBOLS.TRACER);
|
||||||
@@ -84,7 +78,7 @@ export async function bindDevSeedAuth(
|
|||||||
withCapture(
|
withCapture(
|
||||||
logger,
|
logger,
|
||||||
{ feature: "auth", layer: "use-case", name: "auth.signUp" },
|
{ feature: "auth", layer: "use-case", name: "auth.signUp" },
|
||||||
signUpUseCase(repo, authService, bus),
|
signUpUseCase(repo, authService, bus as IEventBus),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
const wrappedSignOut = withSpan(
|
const wrappedSignOut = withSpan(
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import type { SanitizedConfig } from "payload";
|
|
||||||
import {
|
import {
|
||||||
withSpan,
|
withSpan,
|
||||||
withCapture,
|
withCapture,
|
||||||
@@ -6,9 +5,8 @@ import {
|
|||||||
type ITracer,
|
type ITracer,
|
||||||
type ILogger,
|
type ILogger,
|
||||||
} from "@repo/core-shared/instrumentation";
|
} from "@repo/core-shared/instrumentation";
|
||||||
|
import type { BindProductionContext } from "@repo/core-shared/di";
|
||||||
import type { IEventBus } from "@repo/core-events";
|
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 { authContainer } from "./container";
|
||||||
import { AUTH_SYMBOLS } from "./symbols";
|
import { AUTH_SYMBOLS } from "./symbols";
|
||||||
import { UsersRepository } from "../infrastructure/repositories/users.repository";
|
import { UsersRepository } from "../infrastructure/repositories/users.repository";
|
||||||
@@ -24,18 +22,12 @@ import type { IAuthenticationService } from "../application/services/authenticat
|
|||||||
|
|
||||||
let bound = false;
|
let bound = false;
|
||||||
|
|
||||||
export function bindProductionAuth(
|
export function bindProductionAuth(ctx: BindProductionContext): void {
|
||||||
config: SanitizedConfig,
|
|
||||||
tracer: ITracer,
|
|
||||||
logger: ILogger,
|
|
||||||
bus: IEventBus,
|
|
||||||
queue: IJobQueue,
|
|
||||||
realtime: IRealtimeBroadcaster,
|
|
||||||
realtimeRegistry: IRealtimeHandlerRegistry,
|
|
||||||
): void {
|
|
||||||
if (bound) return;
|
if (bound) return;
|
||||||
bound = true;
|
bound = true;
|
||||||
|
|
||||||
|
const { config, tracer, logger, bus, queue, realtime, realtimeRegistry } = ctx;
|
||||||
|
|
||||||
// Bind shared instrumentation into feature container
|
// Bind shared instrumentation into feature container
|
||||||
if (authContainer.isBound(INSTRUMENTATION_SYMBOLS.TRACER)) {
|
if (authContainer.isBound(INSTRUMENTATION_SYMBOLS.TRACER)) {
|
||||||
authContainer.unbind(INSTRUMENTATION_SYMBOLS.TRACER);
|
authContainer.unbind(INSTRUMENTATION_SYMBOLS.TRACER);
|
||||||
@@ -77,7 +69,7 @@ export function bindProductionAuth(
|
|||||||
withCapture(
|
withCapture(
|
||||||
logger,
|
logger,
|
||||||
{ feature: "auth", layer: "use-case", name: "auth.signUp" },
|
{ feature: "auth", layer: "use-case", name: "auth.signUp" },
|
||||||
signUpUseCase(repo, authService, bus),
|
signUpUseCase(repo, authService, bus as IEventBus),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
const wrappedSignOut = withSpan(
|
const wrappedSignOut = withSpan(
|
||||||
|
|||||||
Reference in New Issue
Block a user