Skip to content

softDelete

Source Code | Documentation

Allow to mark items as deleted instead of removing them.

ts
  import { 
softDelete
} from 'feathers-utils/hooks';

Type declaration

ts
export type SoftDeleteOptionFunction<H extends HookContext = HookContext> = (
  context?: H,
) => Promisable<{
  [key: string]: any
}>
export interface SoftDeleteOptions<H extends HookContext = HookContext> {
  /**
   * @example { deletedAt: null }
   */
  deletedQuery:
    | {
        [key: string]: any
      }
    | SoftDeleteOptionFunction<H>
  /**
   * @example { deletedAt: new Date() }
   */
  removeData:
    | {
        [key: string]: any
      }
    | SoftDeleteOptionFunction<H>
  /**
   * Transform the params before calling the service method. E.g. remove 'params.provider' or add custom params.
   */
  transformParams?: TransformParamsFn
  /**
   * Key in `params` to disable the soft delete functionality.
   *
   * @default 'disableSoftDelete'
   */
  disableSoftDeleteKey?: string
  /**
   * `softDelete` uses `._patch()` internally to mark items as deleted.
   *
   * If you set this option to `true`, it will use the `.patch()` method with hooks instead.
   */
  usePatchWithHooks?: boolean
}
/**
 * Allow to mark items as deleted instead of removing them.
 *
 * @see https://utils.feathersjs.com/hooks/soft-delete.html
 */
export declare const softDelete: <H extends HookContext = HookContext>(
  options: SoftDeleteOptions<H>,
) => (context: H, next?: NextFunction) => Promise<any>
ArgumentTypeDescription
optionsSoftDeleteOptions<H>
typemethodsmulti
before, aroundfind, get, create, update, patch, removeyes

Released under the MIT License.