[fabric/domain] Refactor use-cases to commands and queries
This commit is contained in:
parent
d56c4bd469
commit
558ee2b9bc
37
packages/fabric/domain/use-case/command.ts
Normal file
37
packages/fabric/domain/use-case/command.ts
Normal 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>;
|
||||
}
|
||||
@ -1,2 +1,3 @@
|
||||
export * from "./use-case-definition.ts";
|
||||
export * from "./command.ts";
|
||||
export * from "./query.ts";
|
||||
export * from "./use-case.ts";
|
||||
|
||||
@ -2,14 +2,14 @@
|
||||
import type { TaggedError } from "@fabric/core";
|
||||
import type { UseCase } from "./use-case.ts";
|
||||
|
||||
export type UseCaseDefinition<
|
||||
export type Query<
|
||||
TDependencies = any,
|
||||
TPayload = any,
|
||||
TOutput = any,
|
||||
TErrors extends TaggedError<string> = any,
|
||||
> = BasicUseCaseDefinition<TDependencies, TPayload, TOutput, TErrors>;
|
||||
> = BasicQueryDefinition<TDependencies, TPayload, TOutput, TErrors>;
|
||||
|
||||
interface BasicUseCaseDefinition<
|
||||
interface BasicQueryDefinition<
|
||||
TDependencies,
|
||||
TPayload,
|
||||
TOutput,
|
||||
@ -25,6 +25,11 @@ interface BasicUseCaseDefinition<
|
||||
*/
|
||||
isAuthRequired: boolean;
|
||||
|
||||
/**
|
||||
* Permissions required to execute the use case.
|
||||
*/
|
||||
permissions?: string[];
|
||||
|
||||
/**
|
||||
* The use case function.
|
||||
*/
|
||||
Loading…
Reference in New Issue
Block a user