UNPKG

6.92 kBTypeScriptView Raw
1import type { Aggregate, Query } from 'mongoose';
2import { mongoose } from './typegoose';
3import type { DocumentType, EmptyVoidFn } from './types';
4declare type NumberOrDocumentOrDocumentArray<T> = number | DocumentType<T> | DocumentType<T>[];
5declare type ReturnVoid = void | Promise<void>;
6declare type HookNextErrorFn = (err?: Error) => ReturnVoid;
7declare type PreFnWithAggregate<T> = (this: Aggregate<T>, next: (error?: Error) => ReturnVoid) => ReturnVoid;
8declare type PreFnWithDocumentType<T> = (this: DocumentType<T>, next: HookNextErrorFn) => ReturnVoid;
9declare type PreFnWithQuery<T> = (this: Query<any, DocumentType<T>>, next: (error?: Error) => ReturnVoid) => ReturnVoid;
10declare type ModelPostFn<T> = (result: any, next: EmptyVoidFn) => ReturnVoid;
11declare type PostNumberResponse<T> = (result: number, next: EmptyVoidFn) => ReturnVoid;
12declare type PostSingleResponse<T> = (result: DocumentType<T>, next: EmptyVoidFn) => ReturnVoid;
13declare type PostMultipleResponse<T> = (result: DocumentType<T>[], next: EmptyVoidFn) => ReturnVoid;
14declare type PostRegExpResponse<T> = (result: NumberOrDocumentOrDocumentArray<T>, next: EmptyVoidFn) => ReturnVoid;
15declare type PostArrayResponse<T> = (result: NumberOrDocumentOrDocumentArray<T>, next: EmptyVoidFn) => ReturnVoid;
16declare type PostQueryArrayResponse<T> = (this: Query<any, DocumentType<T>>, result: NumberOrDocumentOrDocumentArray<T>, next: EmptyVoidFn) => ReturnVoid;
17declare type PostNumberWithError<T> = (error: Error, result: number, next: HookNextErrorFn) => ReturnVoid;
18declare type PostSingleWithError<T> = (error: Error, result: DocumentType<T>, next: HookNextErrorFn) => ReturnVoid;
19declare type PostMultipleWithError<T> = (error: Error, result: DocumentType<T>[], next: HookNextErrorFn) => ReturnVoid;
20declare type PostRegExpWithError<T> = (error: Error, result: NumberOrDocumentOrDocumentArray<T>, next: HookNextErrorFn) => ReturnVoid;
21declare type PostArrayWithError<T> = (error: Error, result: NumberOrDocumentOrDocumentArray<T>, next: EmptyVoidFn) => ReturnVoid;
22declare type PostQueryArrayWithError<T> = (this: Query<any, DocumentType<T>>, error: Error, result: NumberOrDocumentOrDocumentArray<T>, next: EmptyVoidFn) => ReturnVoid;
23declare type AggregateMethod = 'aggregate';
24declare type DocumentMethod = 'init' | 'validate' | 'save' | 'remove';
25declare type NumberMethod = 'count';
26declare type SingleMethod = 'findOne' | 'findOneAndRemove' | 'findOneAndUpdate' | 'findOneAndDelete' | 'deleteOne' | DocumentMethod;
27declare type MultipleMethod = 'find' | 'update' | 'deleteMany' | 'aggregate';
28declare type QueryMethod = 'count' | 'countDocuments' | 'estimatedDocumentCount' | 'find' | 'findOne' | 'findOneAndRemove' | 'findOneAndUpdate' | 'update' | 'updateOne' | 'updateMany' | 'findOneAndDelete' | 'deleteOne' | 'deleteMany';
29declare type ModelMethod = 'insertMany';
30declare type QMR = QueryMethod | ModelMethod | RegExp;
31declare type DR = DocumentMethod | RegExp;
32export declare const pre: {
33 <T>(method: AggregateMethod, fn: PreFnWithAggregate<T>, options?: mongoose.SchemaPreOptions): ClassDecorator;
34 <T_1>(method: DR | DR[], fn: PreFnWithDocumentType<T_1>, options?: mongoose.SchemaPreOptions): ClassDecorator;
35 <T_2>(method: QMR | QMR[], fn: PreFnWithQuery<T_2>, options?: mongoose.SchemaPreOptions): ClassDecorator;
36};
37export declare const post: {
38 <T>(method: RegExp, fn: PostRegExpResponse<T>, options?: mongoose.SchemaPostOptions): ClassDecorator;
39 <T_1>(method: RegExp, fn: PostRegExpWithError<T_1>, options?: mongoose.SchemaPostOptions): ClassDecorator;
40 <T_2>(method: NumberMethod, fn: PostNumberResponse<T_2>, options?: mongoose.SchemaPostOptions): ClassDecorator;
41 <T_3>(method: NumberMethod, fn: PostNumberWithError<T_3>, options?: mongoose.SchemaPostOptions): ClassDecorator;
42 <T_4>(method: SingleMethod, fn: PostSingleResponse<T_4>, options?: mongoose.SchemaPostOptions): ClassDecorator;
43 <T_5>(method: SingleMethod, fn: PostSingleWithError<T_5>, options?: mongoose.SchemaPostOptions): ClassDecorator;
44 <T_6>(method: MultipleMethod, fn: PostMultipleResponse<T_6>, options?: mongoose.SchemaPostOptions): ClassDecorator;
45 <T_7>(method: MultipleMethod, fn: PostMultipleWithError<T_7>, options?: mongoose.SchemaPostOptions): ClassDecorator;
46 <T_8>(method: ModelMethod, fn: ModelPostFn<T_8> | PostMultipleResponse<T_8>, options?: mongoose.SchemaPostOptions): ClassDecorator;
47 <T_9>(method: DocumentMethod | DocumentMethod[], fn: PostArrayResponse<T_9>, options?: mongoose.SchemaPostOptions): ClassDecorator;
48 <T_10>(method: DocumentMethod | DocumentMethod[], fn: PostArrayWithError<T_10>, options?: mongoose.SchemaPostOptions): ClassDecorator;
49 <T_11>(method: QMR | QMR[], fn: PostQueryArrayResponse<T_11>, options?: mongoose.SchemaPostOptions): ClassDecorator;
50 <T_12>(method: QMR | QMR[], fn: PostQueryArrayWithError<T_12>, options?: mongoose.SchemaPostOptions): ClassDecorator;
51};
52export declare const Pre: {
53 <T>(method: AggregateMethod, fn: PreFnWithAggregate<T>, options?: mongoose.SchemaPreOptions): ClassDecorator;
54 <T_1>(method: DR | DR[], fn: PreFnWithDocumentType<T_1>, options?: mongoose.SchemaPreOptions): ClassDecorator;
55 <T_2>(method: QMR | QMR[], fn: PreFnWithQuery<T_2>, options?: mongoose.SchemaPreOptions): ClassDecorator;
56};
57export declare const Post: {
58 <T>(method: RegExp, fn: PostRegExpResponse<T>, options?: mongoose.SchemaPostOptions): ClassDecorator;
59 <T_1>(method: RegExp, fn: PostRegExpWithError<T_1>, options?: mongoose.SchemaPostOptions): ClassDecorator;
60 <T_2>(method: NumberMethod, fn: PostNumberResponse<T_2>, options?: mongoose.SchemaPostOptions): ClassDecorator;
61 <T_3>(method: NumberMethod, fn: PostNumberWithError<T_3>, options?: mongoose.SchemaPostOptions): ClassDecorator;
62 <T_4>(method: SingleMethod, fn: PostSingleResponse<T_4>, options?: mongoose.SchemaPostOptions): ClassDecorator;
63 <T_5>(method: SingleMethod, fn: PostSingleWithError<T_5>, options?: mongoose.SchemaPostOptions): ClassDecorator;
64 <T_6>(method: MultipleMethod, fn: PostMultipleResponse<T_6>, options?: mongoose.SchemaPostOptions): ClassDecorator;
65 <T_7>(method: MultipleMethod, fn: PostMultipleWithError<T_7>, options?: mongoose.SchemaPostOptions): ClassDecorator;
66 <T_8>(method: ModelMethod, fn: ModelPostFn<T_8> | PostMultipleResponse<T_8>, options?: mongoose.SchemaPostOptions): ClassDecorator;
67 <T_9>(method: DocumentMethod | DocumentMethod[], fn: PostArrayResponse<T_9>, options?: mongoose.SchemaPostOptions): ClassDecorator;
68 <T_10>(method: DocumentMethod | DocumentMethod[], fn: PostArrayWithError<T_10>, options?: mongoose.SchemaPostOptions): ClassDecorator;
69 <T_11>(method: QMR | QMR[], fn: PostQueryArrayResponse<T_11>, options?: mongoose.SchemaPostOptions): ClassDecorator;
70 <T_12>(method: QMR | QMR[], fn: PostQueryArrayWithError<T_12>, options?: mongoose.SchemaPostOptions): ClassDecorator;
71};
72export {};