Files
agentic-dev/turbo/generators/templates/feature/src/di/bind-dev-seed.ts.hbs
Danijel Martinek e17d60b8ac feat(navigation): update feature generator templates to emit wireUseCase
Replace inline withSpan(withCapture(factory(deps))) form in the binder
templates with wireUseCase({...}) calls so newly scaffolded features are
consistent with the migrated production features.

Also add assertFeatureConformance to bind-dev-seed.ts.hbs (aligns with
the migrated auth/navigation pattern) and fix bind-dev-seed.test.ts.hbs
to call binders with the ctx object form (BindContext) instead of the old
two-argument (tracer, logger) form.

Verified by running turbo gen feature testfeature and confirming:
  - Generated binders use wireUseCase for use cases
  - All 5 conformance gates pass on the scaffold
  - Scaffold cleaned up post-verification

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-13 18:36:30 +00:00

101 lines
4.2 KiB
Handlebars

import {
withSpan,
withCapture,
INSTRUMENTATION_SYMBOLS,
type ITracer,
type ILogger,
} from "@repo/core-shared/instrumentation";
import type { BindContext } from "@repo/core-shared/di";
import {
assertFeatureConformance,
wireUseCase,
} from "@repo/core-shared/conformance";
import { {{camelCase name}}Manifest } from "../feature.manifest.js";
import { {{camelCase name}}Container } from "./container.js";
import { {{constantCase name}}_SYMBOLS } from "./symbols.js";
import { Mock{{pascalCase entity}}Repository } from "../infrastructure/repositories/{{kebabCase entity}}.repository.mock.js";
import { buildDev{{pascalCase entity}}Map } from "../__seeds__/dev.js";
import { get{{pascalCase entity}}UseCase } from "../application/use-cases/get-{{kebabCase entity}}.use-case.js";
import { get{{pascalCase entity}}Controller } from "../interface-adapters/controllers/get-{{kebabCase entity}}.controller.js";
import type { I{{pascalCase entity}}Repository } from "../application/repositories/{{kebabCase entity}}.repository.interface.js";
/**
* Replace the default mock with a populated one for dev mode + storybook.
*
* Mutually exclusive with `bindProduction{{pascalCase name}}(ctx)`.
* Tests must NOT call this — they construct `new Mock{{pascalCase entity}}Repository()`
* directly and seed via factories per-test.
*
* Idempotent: safe to call multiple times; each call rebuilds a fresh
* populated repo and rebinds the symbol.
*/
export async function bindDevSeed{{pascalCase name}}(ctx: BindContext): Promise<void> {
const { tracer, logger, bus, queue, realtime, realtimeRegistry } = ctx;
// Bind shared instrumentation into feature container
if ({{camelCase name}}Container.isBound(INSTRUMENTATION_SYMBOLS.TRACER)) {
{{camelCase name}}Container.unbind(INSTRUMENTATION_SYMBOLS.TRACER);
}
if ({{camelCase name}}Container.isBound(INSTRUMENTATION_SYMBOLS.LOGGER)) {
{{camelCase name}}Container.unbind(INSTRUMENTATION_SYMBOLS.LOGGER);
}
{{camelCase name}}Container.bind<ITracer>(INSTRUMENTATION_SYMBOLS.TRACER).toConstantValue(tracer);
{{camelCase name}}Container.bind<ILogger>(INSTRUMENTATION_SYMBOLS.LOGGER).toConstantValue(logger);
if ({{camelCase name}}Container.isBound({{constantCase name}}_SYMBOLS.I{{pascalCase entity}}Repository)) {
{{camelCase name}}Container.unbind({{constantCase name}}_SYMBOLS.I{{pascalCase entity}}Repository);
}
const repo = new Mock{{pascalCase entity}}Repository(buildDev{{pascalCase entity}}Map(), tracer, logger);
{{camelCase name}}Container
.bind<I{{pascalCase entity}}Repository>({{constantCase name}}_SYMBOLS.I{{pascalCase entity}}Repository)
.toConstantValue(repo);
// Use case
const wrappedGet{{pascalCase entity}} = wireUseCase({
container: {{camelCase name}}Container,
symbol: {{constantCase name}}_SYMBOLS.IGet{{pascalCase entity}}UseCase,
factory: get{{pascalCase entity}}UseCase,
deps: [repo],
feature: "{{kebabCase name}}",
layer: "use-case",
name: "get{{pascalCase entity}}",
tracer,
logger,
});
if ({{camelCase name}}Container.isBound({{constantCase name}}_SYMBOLS.IGet{{pascalCase entity}}Controller)) {
{{camelCase name}}Container.unbind({{constantCase name}}_SYMBOLS.IGet{{pascalCase entity}}Controller);
}
{{camelCase name}}Container
.bind({{constantCase name}}_SYMBOLS.IGet{{pascalCase entity}}Controller)
.toConstantValue(
withSpan(
tracer,
{ name: "{{camelCase name}}.get{{pascalCase entity}}", op: "controller" },
withCapture(
logger,
{ feature: "{{kebabCase name}}", layer: "controller", name: "{{camelCase name}}.get{{pascalCase entity}}" },
get{{pascalCase entity}}Controller(wrappedGet{{pascalCase entity}}),
),
),
);
// bus + queue are passed through; generated handlers consume them at the anchors below.
void bus;
void queue;
void realtime;
void realtimeRegistry;
// <gen:event-handlers>
// <gen:jobs>
// <gen:realtime-handlers>
// Boot-time conformance check (dev-seed mode).
assertFeatureConformance(
{{camelCase name}}Container,
{{camelCase name}}Manifest,
{
get{{pascalCase entity}}: {{constantCase name}}_SYMBOLS.IGet{{pascalCase entity}}UseCase,
},
ctx,
);
}