Files
agentic-dev/packages/workspaces/src/application/use-cases/get-workspace-status.use-case.ts
Danijel Martinek eec402d49d feat(workspaces): status and list use cases
getWorkspaceStatus returns persisted { id, status } only (runner-driven
transitions arrive in story 07); listWorkspaces returns the
credential-free workspace array with a strict void input (optional on
the tRPC procedure so clients can call without args). Repository gains
listWorkspaces on interface, mock, and Payload impl; the contract suite
covers listing incl. the never-returns-credentials guarantee.
Controller span+capture wrapping is extracted into a shared
bindWorkspacesController helper used by both binders, trimming the
bind-production/bind-dev-seed clone family fallow was flagging.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016j8z4VHjedXDTjEDNg7qHK
2026-07-12 22:36:18 +02:00

45 lines
1.9 KiB
TypeScript

import { z } from "zod";
import { WorkspaceNotFoundError } from "../../entities/errors/workspace";
import { workspaceSchema } from "../../entities/models/workspace";
import type { IWorkspaceRepository } from "../repositories/workspace.repository.interface";
// ── Input ────────────────────────────────────────────────────────────────
export const getWorkspaceStatusInputSchema = z
.object({
id: z.string().min(1),
})
.strict();
export type GetWorkspaceStatusInput = z.infer<
typeof getWorkspaceStatusInputSchema
>;
// ── Output ───────────────────────────────────────────────────────────────
// Persisted state only in this story — runner-driven transitions (story 07)
// extend the status enum, not this shape.
export const getWorkspaceStatusOutputSchema = workspaceSchema.pick({
id: true,
status: true,
});
export type GetWorkspaceStatusOutput = z.infer<
typeof getWorkspaceStatusOutputSchema
>;
// ── Use case ─────────────────────────────────────────────────────────────
export type IGetWorkspaceStatusUseCase = ReturnType<
typeof getWorkspaceStatusUseCase
>;
export const getWorkspaceStatusUseCase =
(workspaceRepository: IWorkspaceRepository) =>
async (input: GetWorkspaceStatusInput): Promise<GetWorkspaceStatusOutput> => {
const workspace = await workspaceRepository.getWorkspace(input.id);
if (!workspace) {
throw new WorkspaceNotFoundError(`Workspace not found: ${input.id}`);
}
return getWorkspaceStatusOutputSchema.parse({
id: workspace.id,
status: workspace.status,
});
};