Files
gridpilot.gg/apps/website/lib/contracts/mutations/Mutation.ts
2026-01-13 00:16:14 +01:00

35 lines
966 B
TypeScript

import { Result } from "../Result";
/**
* Mutation Contract
*
* Purpose: Framework-agnostic write operations
*
* Rules:
* - Orchestrates services for writes
* - No HTTP/API calls directly
* - No 'use client' directive
* - No 'use server' directive
* - Must be in lib/mutations/
* - Must be named *Mutation
* - Can be called from Server Actions
* - Single responsibility: ONE operation per mutation
*
* Pattern:
* Server Action → Mutation → Service → API Client
*
* Design Principle:
* Each mutation does ONE thing. If you need multiple operations,
* create multiple mutation classes (e.g., UpdateUserStatusMutation, DeleteUserMutation).
* This follows the same pattern as Page Queries.
*/
export interface Mutation<TInput = void, TOutput = void> {
/**
* Execute the mutation
*
* @param input - Mutation input
* @returns Result indicating success or error
*/
execute(input: TInput): Promise<Result<TOutput, string>>;
}