[fabric/domain] Refactor use-cases to commands and queries

This commit is contained in:
Pablo Baleztena 2024-10-16 16:18:19 -03:00
parent d56c4bd469
commit 558ee2b9bc
3 changed files with 47 additions and 4 deletions

View File

@ -0,0 +1,37 @@
// deno-lint-ignore-file no-explicit-any
import type { TaggedError } from "@fabric/core";
import type { UseCase } from "./use-case.ts";
export type Command<
TDependencies = any,
TPayload = any,
TEvent extends Event = any,
TErrors extends TaggedError<string> = any,
> = BasicCommandDefinition<TDependencies, TPayload, TEvent, TErrors>;
interface BasicCommandDefinition<
TDependencies,
TPayload,
TEvent extends Event,
TErrors extends TaggedError<string>,
> {
/**
* The use case name.
*/
name: string;
/**
* Whether the use case requires authentication or not.
*/
isAuthRequired: boolean;
/**
* Permissions required to execute the use case.
*/
permissions?: string[];
/**
* The use case function.
*/
useCase: UseCase<TDependencies, TPayload, TEvent, TErrors>;
}

View File

@ -1,2 +1,3 @@
export * from "./use-case-definition.ts"; export * from "./command.ts";
export * from "./query.ts";
export * from "./use-case.ts"; export * from "./use-case.ts";

View File

@ -2,14 +2,14 @@
import type { TaggedError } from "@fabric/core"; import type { TaggedError } from "@fabric/core";
import type { UseCase } from "./use-case.ts"; import type { UseCase } from "./use-case.ts";
export type UseCaseDefinition< export type Query<
TDependencies = any, TDependencies = any,
TPayload = any, TPayload = any,
TOutput = any, TOutput = any,
TErrors extends TaggedError<string> = any, TErrors extends TaggedError<string> = any,
> = BasicUseCaseDefinition<TDependencies, TPayload, TOutput, TErrors>; > = BasicQueryDefinition<TDependencies, TPayload, TOutput, TErrors>;
interface BasicUseCaseDefinition< interface BasicQueryDefinition<
TDependencies, TDependencies,
TPayload, TPayload,
TOutput, TOutput,
@ -25,6 +25,11 @@ interface BasicUseCaseDefinition<
*/ */
isAuthRequired: boolean; isAuthRequired: boolean;
/**
* Permissions required to execute the use case.
*/
permissions?: string[];
/** /**
* The use case function. * The use case function.
*/ */