diff --git a/packages/fabric/domain/use-case/command.ts b/packages/fabric/domain/use-case/command.ts new file mode 100644 index 0000000..5280260 --- /dev/null +++ b/packages/fabric/domain/use-case/command.ts @@ -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 = any, +> = BasicCommandDefinition; + +interface BasicCommandDefinition< + TDependencies, + TPayload, + TEvent extends Event, + TErrors extends TaggedError, +> { + /** + * 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; +} diff --git a/packages/fabric/domain/use-case/index.ts b/packages/fabric/domain/use-case/index.ts index b2be5af..3375c3a 100644 --- a/packages/fabric/domain/use-case/index.ts +++ b/packages/fabric/domain/use-case/index.ts @@ -1,2 +1,3 @@ -export * from "./use-case-definition.ts"; +export * from "./command.ts"; +export * from "./query.ts"; export * from "./use-case.ts"; diff --git a/packages/fabric/domain/use-case/use-case-definition.ts b/packages/fabric/domain/use-case/query.ts similarity index 73% rename from packages/fabric/domain/use-case/use-case-definition.ts rename to packages/fabric/domain/use-case/query.ts index 1eb4726..754e5e5 100644 --- a/packages/fabric/domain/use-case/use-case-definition.ts +++ b/packages/fabric/domain/use-case/query.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 = any, -> = BasicUseCaseDefinition; +> = BasicQueryDefinition; -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. */