import { assert , createError , isCustomError } from '@syncot/util' ; export interface AlreadyExistsError extends Error { name : 'SyncOTError AlreadyExists' ; entityName : string ; entity : any ; key : string | null ; value : any ; } param entityName param entity param key param value export function createAlreadyExistsError ( entityName , entity , key = null , value = null ) { assert ( typeof entityName === 'string' , 'Argument "entityName" must be a string.' ) ; assert ( typeof key === 'string' || key === null , 'Argument "key" must be a string or null.' ) ; return createError ( { entity , entityName , key , value , message : `"${ entityName }" already exists.` , name : 'SyncOTError AlreadyExists' , } ) as AlreadyExistsError ; } export function isAlreadyExistsError ( error ) { return isCustomError ( error ) && error . name === 'SyncOTError AlreadyExists' ; } export interface NotFoundError extends Error { name : 'SyncOTError NotFound' ; entityName : string ; } export function createNotFoundError ( entityName ) { assert ( typeof entityName === 'string' , 'Argument "entityName" must be a string.' ) ; return createError ( { entityName , message : `"${ entityName }" not found.` , name : 'SyncOTError NotFound' , } ) as NotFoundError ; } export function isNotFoundError ( error ) { return isCustomError ( error ) && error . name === 'SyncOTError NotFound' ; } export interface SchemaConflictError extends Error { name : 'SyncOTError SchemaConflict' ; } export function createSchemaConflictError ( message ) { return createError ( { message , name : 'SyncOTError SchemaConflict' , } ) as SchemaConflictError ; } export function isSchemaConflictError ( error ) { return isCustomError ( error ) && error . name === 'SyncOTError SchemaConflict' ; }