-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.d.ts
108 lines (100 loc) · 4.05 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Type definitions for mongoose-delete 0.5
// WARNING!!! These typings have been modified just to get the code working with 5.12 while matching the implementation being used.
// WARMING!!! These typings do NOT cover mongoose-delete correctly in all use cases
// Project: https://github.com/dsanel/mongoose-delete
// Definitions by: Mochamad Arifin <https://github.com/ndunks>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.2
import mongoose = require('mongoose');
import {Document, Model} from "mongoose";
/**
* This is interface helper to declaring model that using Soft Delete
*/
declare namespace mongoose_delete {
interface Callback<T, THIS = T> {
(this: THIS, err: any, doc: T): void;
}
type overridableMethods =
| 'count'
| 'countDocuments'
| 'find'
| 'findOne'
| 'findOneAndUpdate'
| 'update';
interface SoftDeleteModel<T extends mongoose.Document, QueryHelpers = {}>
extends mongoose.Model<T, QueryHelpers> {
/** Count only deleted documents */
countDeleted: typeof mongoose.Model.count;
/** Count all documents including deleted */
countWithDeleted: typeof mongoose.Model.count;
/** Find only deleted documents */
findDeleted: typeof mongoose.Model.find;
/** Find all documents including deleted */
findWithDeleted: typeof mongoose.Model.find;
/** Find One only deleted documents */
findOneDeleted: typeof mongoose.Model.findOne;
/** Find One all documents including deleted */
findOneWithDeleted: typeof mongoose.Model.findOne;
/** Find One And Update only deleted documents */
findOneAndUpdateDeleted: typeof mongoose.Model.findOneAndUpdate;
/** Find One And Update all documents including deleted */
findOneAndUpdateWithDeleted: typeof mongoose.Model.findOneAndUpdate;
/** Update only deleted documents */
updateDeleted: typeof mongoose.Model.update;
/** Update all documents including deleted */
updateWithDeleted: typeof mongoose.Model.update;
/**
* Delete documents by conditions
*/
// delete(conditions?: any, deleteBy?: any, fn?: Callback<T, this>): mongoose.Query<T> & QueryHelpers;
/**
* Restore documents by conditions
*/
// restore(conditions?: any, fn?: Callback<T, this>): mongoose.Query<T> & QueryHelpers;
/**
* Delete a document by ID
*/
deleteById(
id?: string | mongoose.Types.ObjectId /*| Callback<T, this>*/,
// deleteBy?: string | mongoose.Types.ObjectId | mongoose.Document | Callback<T, this>,
// fn?: Callback<T, this>,
): mongoose.Query<T> & QueryHelpers;
}
interface SoftDeleteDocument
extends mongoose.Document,
SoftDeleteInterface {
/** Soft delete this document */
// delete(
// deleteBy?: string | mongoose.Types.ObjectId | Callback<this>,
// fn?: Callback<this>,
// ): Promise<this>;
restore(fn?: Callback<this>): Promise<this>;
}
interface SoftDeleteInterface {
/** Soft deleted ? */
deleted?: boolean;
deleteAt?: Date;
deletedBy?: mongoose.Types.ObjectId | string | mongoose.Document;
}
}
interface Options {
overrideMethods: boolean | 'all' | mongoose_delete.overridableMethods[];
deletedAt: boolean;
deletedBy: boolean;
indexFields: boolean | 'all' | Array<keyof mongoose_delete.SoftDeleteInterface>;
validateBeforeDelete: boolean;
/**
* DeleteBy Schema type, equal to
* ```
* Schema({
* deletedBy: {
* type: options.deletedByType
* }
* })
* ```
* @default ObjectId
*/
deletedByType: any;
}
declare function mongoose_delete<DocType = Document, M extends Model<DocType, any, any> = Model<any, any, any>, SchemaDefinitionType = undefined>(schema: mongoose.Schema<DocType, M, SchemaDefinitionType>, options?: Partial<Options>): void;
export = mongoose_delete;