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:
@@ -0,0 +1,35 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { get{{pascalCase entity}}Controller } from "@/interface-adapters/controllers/get-{{kebabCase entity}}.controller";
|
||||
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 { InputParseError } from "@/entities/errors/common";
|
||||
|
||||
describe("get{{pascalCase entity}}Controller", () => {
|
||||
it("returns the {{camelCase entity}} for a valid id", async () => {
|
||||
const repo = new Mock{{pascalCase entity}}Repository();
|
||||
const useCase = get{{pascalCase entity}}UseCase(repo);
|
||||
const controller = get{{pascalCase entity}}Controller(useCase);
|
||||
|
||||
const result = await controller({ id: "seed-1" });
|
||||
|
||||
expect(result.id).toBe("seed-1");
|
||||
});
|
||||
|
||||
it("throws InputParseError when input is missing fields", async () => {
|
||||
const repo = new Mock{{pascalCase entity}}Repository();
|
||||
const useCase = get{{pascalCase entity}}UseCase(repo);
|
||||
const controller = get{{pascalCase entity}}Controller(useCase);
|
||||
|
||||
await expect(controller({})).rejects.toBeInstanceOf(InputParseError);
|
||||
});
|
||||
|
||||
it("throws InputParseError when input has unexpected fields (strict)", async () => {
|
||||
const repo = new Mock{{pascalCase entity}}Repository();
|
||||
const useCase = get{{pascalCase entity}}UseCase(repo);
|
||||
const controller = get{{pascalCase entity}}Controller(useCase);
|
||||
|
||||
await expect(
|
||||
controller({ id: "seed-1", unexpected: true }),
|
||||
).rejects.toBeInstanceOf(InputParseError);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,23 @@
|
||||
import { InputParseError } from "../../entities/errors/common";
|
||||
import {
|
||||
get{{pascalCase entity}}InputSchema,
|
||||
type Get{{pascalCase entity}}Output,
|
||||
type IGet{{pascalCase entity}}UseCase,
|
||||
} from "../../application/use-cases/get-{{kebabCase entity}}.use-case";
|
||||
|
||||
function presenter(value: Get{{pascalCase entity}}Output) {
|
||||
return value;
|
||||
}
|
||||
|
||||
export type IGet{{pascalCase entity}}Controller = ReturnType<typeof get{{pascalCase entity}}Controller>;
|
||||
|
||||
export const get{{pascalCase entity}}Controller =
|
||||
(get{{pascalCase entity}}UseCase: IGet{{pascalCase entity}}UseCase) =>
|
||||
async (input: unknown): Promise<ReturnType<typeof presenter>> => {
|
||||
const parsed = get{{pascalCase entity}}InputSchema.safeParse(input);
|
||||
if (!parsed.success) {
|
||||
throw new InputParseError("Invalid get-{{kebabCase entity}} input", { cause: parsed.error });
|
||||
}
|
||||
const result = await get{{pascalCase entity}}UseCase(parsed.data);
|
||||
return presenter(result);
|
||||
};
|
||||
Reference in New Issue
Block a user