feat(turbo): turbo gen feature generator (Phase 1, single-entity)

Adds `pnpm turbo gen feature` to scaffold a Lazar-conformant feature
package matching the navigation reference shape: entity + Zod schema,
single use case (`get<Entity>`), controller, mock + Payload-stub real
repository (with span + capture), DI module/container/symbols, and tRPC
router with full BAD_REQUEST/NOT_FOUND error mapping. The generated
`bind-production.ts` and `bind-dev-seed.ts` compose the post-R44
`withSpan(tracer, opts, withCapture(logger, tags, factory(deps)))`
sandwich at bind time.

Verified by generating a sample `packages/example/` feature and running
`pnpm --filter @repo/example lint typecheck test` — all three pass
(9 test files, 25 tests). Cleaned up after verification so no example
package is committed.

Phase-1 limitations (documented in `docs/guides/scaffolding-a-feature.md`
and printed by the generator on success): no Payload CMS templates, no
React Query helpers, faker-driven factories left as stubs, single
entity / single use case, and aggregator wiring (core-api/root,
apps/web-next bindAll) is left as a manual checklist.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-08 01:09:22 +02:00
parent b4ec48f058
commit 019d4866a0
40 changed files with 1769 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
import { describe, expect, it } from "vitest";
import { ZodError } from "zod";
import { get{{pascalCase entity}}UseCase } from "@/application/use-cases/get-{{kebabCase entity}}.use-case";
import { Mock{{pascalCase entity}}Repository } from "@/infrastructure/repositories/{{kebabCase entity}}.repository.mock";
import { {{pascalCase entity}}NotFoundError } from "@/entities/errors/{{kebabCase entity}}";
describe("get{{pascalCase entity}}UseCase", () => {
it("returns the seeded {{camelCase entity}} by id", async () => {
const repo = new Mock{{pascalCase entity}}Repository();
const useCase = get{{pascalCase entity}}UseCase(repo);
const result = await useCase({ id: "seed-1" });
expect(result.id).toBe("seed-1");
expect(result.name).toBeTypeOf("string");
});
it("throws {{pascalCase entity}}NotFoundError when repository returns null", async () => {
const repo = new Mock{{pascalCase entity}}Repository(new Map());
const useCase = get{{pascalCase entity}}UseCase(repo);
await expect(useCase({ id: "missing" })).rejects.toBeInstanceOf(
{{pascalCase entity}}NotFoundError,
);
});
it("throws ZodError when repository returns malformed data", async () => {
const malformedRepo = {
get{{pascalCase entity}}: async () => ({ id: "", name: "x" }) as never,
};
const useCase = get{{pascalCase entity}}UseCase(malformedRepo);
await expect(useCase({ id: "anything" })).rejects.toBeInstanceOf(ZodError);
});
});

View File

@@ -0,0 +1,30 @@
import { z } from "zod";
import { {{pascalCase entity}}NotFoundError } from "../../entities/errors/{{kebabCase entity}}";
import { {{camelCase entity}}Schema } from "../../entities/models/{{kebabCase entity}}";
import type { I{{pascalCase entity}}Repository } from "../repositories/{{kebabCase entity}}.repository.interface";
// ── Input ────────────────────────────────────────────────────────────────
export const get{{pascalCase entity}}InputSchema = z
.object({
id: z.string().min(1),
})
.strict();
export type Get{{pascalCase entity}}Input = z.infer<typeof get{{pascalCase entity}}InputSchema>;
// ── Output ───────────────────────────────────────────────────────────────
export const get{{pascalCase entity}}OutputSchema = {{camelCase entity}}Schema;
export type Get{{pascalCase entity}}Output = z.infer<typeof get{{pascalCase entity}}OutputSchema>;
// ── Use case ─────────────────────────────────────────────────────────────
export type IGet{{pascalCase entity}}UseCase = ReturnType<typeof get{{pascalCase entity}}UseCase>;
export const get{{pascalCase entity}}UseCase =
({{camelCase entity}}Repository: I{{pascalCase entity}}Repository) =>
async (input: Get{{pascalCase entity}}Input): Promise<Get{{pascalCase entity}}Output> => {
const result = await {{camelCase entity}}Repository.get{{pascalCase entity}}(input.id);
if (!result) {
throw new {{pascalCase entity}}NotFoundError(`{{pascalCase entity}} not found: ${input.id}`);
}
return get{{pascalCase entity}}OutputSchema.parse(result);
};