mongoose-advanced-soft-delete
Version:
Lightweight Mongoose Plugin for Effortless Soft Deletion
31 lines (26 loc) • 1.53 kB
text/typescript
import { Document, Model, FilterQuery, ProjectionType, QueryOptions, Schema } from 'mongoose';
interface SoftDeleteDocument extends Document {
isDeleted: boolean;
deletedAt: Date | null;
}
type GenericSoftDeleteDocument<T> = T & SoftDeleteDocument;
interface SoftDeleteModel<T> extends Model<GenericSoftDeleteDocument<T>> {
findDeleted(): Promise<GenericSoftDeleteDocument<T>[]>;
findAllIncludingSoftDeleted(query: FilterQuery<GenericSoftDeleteDocument<T>>, projection?: ProjectionType<GenericSoftDeleteDocument<T>>, options?: QueryOptions<GenericSoftDeleteDocument<T>>): Promise<GenericSoftDeleteDocument<T>[]>;
findOneIncludingSoftDeleted: (query: FilterQuery<SoftDeleteDocument>, projection?: ProjectionType<SoftDeleteDocument>, options?: QueryOptions<SoftDeleteDocument>) => Promise<GenericSoftDeleteDocument<T> | null>;
restore(query: object): Promise<{
restored: number;
}>;
softDeleteById(id: string, options?: object): Promise<{
deletedCount: number;
} | null>;
softDelete(query: object, options?: object): Promise<{
deletedCount: number;
} | null>;
softDeleteMany(query: object, options?: object): Promise<{
deletedCount: number;
} | null>;
}
declare const softDeletePlugin: (schema: Schema) => void;
declare const applyNotDeletedFilter: (this: FilterQuery<SoftDeleteDocument>, next: () => void) => void;
export { type GenericSoftDeleteDocument, type SoftDeleteDocument, type SoftDeleteModel, applyNotDeletedFilter, softDeletePlugin };