[fabric/domain] Add assertNone method and AlreadyExistsError class to StoreQuery interfaces

This commit is contained in:
Pablo Baleztena 2024-10-30 22:41:14 -03:00
parent ae61c03bb9
commit 60c7bacfb5

View File

@ -28,6 +28,8 @@ export interface StoreQuery<T> {
selectOneOrFail<K extends Keyof<T>>( selectOneOrFail<K extends Keyof<T>>(
keys: K[], keys: K[],
): AsyncResult<Pick<T, K>, StoreQueryError | NotFoundError>; ): AsyncResult<Pick<T, K>, StoreQueryError | NotFoundError>;
assertNone(): AsyncResult<void, StoreQueryError | AlreadyExistsError>;
} }
export interface StoreSortableQuery<T> { export interface StoreSortableQuery<T> {
@ -48,6 +50,8 @@ export interface StoreSortableQuery<T> {
selectOneOrFail<K extends Keyof<T>>( selectOneOrFail<K extends Keyof<T>>(
keys: K[], keys: K[],
): AsyncResult<Pick<T, K>, StoreQueryError | NotFoundError>; ): AsyncResult<Pick<T, K>, StoreQueryError | NotFoundError>;
assertNone(): AsyncResult<void, StoreQueryError | AlreadyExistsError>;
} }
export interface StoreLimitableQuery<T> { export interface StoreLimitableQuery<T> {
@ -67,6 +71,8 @@ export interface StoreLimitableQuery<T> {
selectOneOrFail<K extends Keyof<T>>( selectOneOrFail<K extends Keyof<T>>(
keys: K[], keys: K[],
): AsyncResult<Pick<T, K>, StoreQueryError | NotFoundError>; ): AsyncResult<Pick<T, K>, StoreQueryError | NotFoundError>;
assertNone(): AsyncResult<void, StoreQueryError | AlreadyExistsError>;
} }
export interface SelectableQuery<T> { export interface SelectableQuery<T> {
@ -84,6 +90,8 @@ export interface SelectableQuery<T> {
selectOneOrFail<K extends Keyof<T>>( selectOneOrFail<K extends Keyof<T>>(
keys: K[], keys: K[],
): AsyncResult<Pick<T, K>, StoreQueryError | NotFoundError>; ): AsyncResult<Pick<T, K>, StoreQueryError | NotFoundError>;
assertNone(): AsyncResult<void, StoreQueryError | AlreadyExistsError>;
} }
export interface StoreQueryDefinition<K extends string = string> { export interface StoreQueryDefinition<K extends string = string> {
@ -100,3 +108,9 @@ export class NotFoundError extends TaggedError<"NotFoundError"> {
super("NotFoundError"); super("NotFoundError");
} }
} }
export class AlreadyExistsError extends TaggedError<"AlreadyExistsError"> {
constructor() {
super("AlreadyExistsError");
}
}