1 | /// <reference types="mongoose/types/aggregate" />
|
2 | /// <reference types="mongoose/types/callback" />
|
3 | /// <reference types="mongoose/types/collection" />
|
4 | /// <reference types="mongoose/types/connection" />
|
5 | /// <reference types="mongoose/types/cursor" />
|
6 | /// <reference types="mongoose/types/document" />
|
7 | /// <reference types="mongoose/types/error" />
|
8 | /// <reference types="mongoose/types/expressions" />
|
9 | /// <reference types="mongoose/types/helpers" />
|
10 | /// <reference types="mongoose/types/middlewares" />
|
11 | /// <reference types="mongoose/types/indexes" />
|
12 | /// <reference types="mongoose/types/models" />
|
13 | /// <reference types="mongoose/types/mongooseoptions" />
|
14 | /// <reference types="mongoose/types/pipelinestage" />
|
15 | /// <reference types="mongoose/types/populate" />
|
16 | /// <reference types="mongoose/types/query" />
|
17 | /// <reference types="mongoose/types/schemaoptions" />
|
18 | /// <reference types="mongoose/types/schematypes" />
|
19 | /// <reference types="mongoose/types/session" />
|
20 | /// <reference types="mongoose/types/types" />
|
21 | /// <reference types="mongoose/types/utility" />
|
22 | /// <reference types="mongoose/types/validation" />
|
23 | /// <reference types="mongoose/types/virtuals" />
|
24 | /// <reference types="mongoose/types/inferschematype" />
|
25 | /// <reference types="mongoose/types/inferrawdoctype" />
|
26 | import * as mongoose from 'mongoose';
|
27 | import 'reflect-metadata';
|
28 | import { setGlobalOptions } from './globalOptions';
|
29 | import type { AnyParamConstructor, BeAnObject, DocumentType, IModelOptions, Ref, ReturnModelType, SubDocumentType, ArraySubDocumentType } from './types';
|
30 | export { mongoose, setGlobalOptions };
|
31 | export { setLogLevel, LogLevels } from './logSettings';
|
32 | export * from './prop';
|
33 | export * from './hooks';
|
34 | export * from './plugin';
|
35 | export * from './indexes';
|
36 | export * from './searchIndexes';
|
37 | export * from './modelOptions';
|
38 | export * from './queryMethod';
|
39 | export * from './typeguards';
|
40 | export * as defaultClasses from './defaultClasses';
|
41 | export * as errors from './internal/errors';
|
42 | export * as types from './types';
|
43 | export { DocumentType, Ref, ReturnModelType, SubDocumentType, ArraySubDocumentType };
|
44 | export { getClass, getName } from './internal/utils';
|
45 | export { Severity, PropType } from './internal/constants';
|
46 | /**
|
47 | * Build a Model From a Class
|
48 | * @param cl The Class to build a Model from
|
49 | * @param options Overwrite Options, like for naming or general SchemaOptions the class gets compiled with
|
50 | * @returns The finished Model
|
51 | * @public
|
52 | * @example
|
53 | * ```ts
|
54 | * class ClassName {}
|
55 | *
|
56 | * const NameModel = getModelForClass(ClassName);
|
57 | * ```
|
58 | */
|
59 | export declare function getModelForClass<U extends AnyParamConstructor<any>, QueryHelpers = BeAnObject>(cl: U, options?: IModelOptions): ReturnModelType<U, QueryHelpers>;
|
60 | /**
|
61 | * Get Model from internal cache
|
62 | * @param key Model's name key
|
63 | * @example
|
64 | * ```ts
|
65 | * class ClassName {}
|
66 | * getModelForClass(ClassName); // build the model
|
67 | * const NameModel = getModelWithString<typeof ClassName>("ClassName");
|
68 | * ```
|
69 | */
|
70 | export declare function getModelWithString<U extends AnyParamConstructor<any>, QueryHelpers = BeAnObject>(key: string): undefined | ReturnModelType<U, QueryHelpers>;
|
71 | /**
|
72 | * Generates a Mongoose schema out of class props, iterating through all parents
|
73 | * @param cl The Class to build a Schema from
|
74 | * @param options Overwrite Options, like for naming or general SchemaOptions the class gets compiled with
|
75 | * @returns Returns the Build Schema
|
76 | * @example
|
77 | * ```ts
|
78 | * class ClassName {}
|
79 | * const NameSchema = buildSchema(ClassName);
|
80 | * const NameModel = mongoose.model("Name", NameSchema);
|
81 | * ```
|
82 | */
|
83 | export declare function buildSchema<U extends AnyParamConstructor<any>>(cl: U, options?: IModelOptions): mongoose.Schema<DocumentType<InstanceType<U>>>;
|
84 | /**
|
85 | * Add a Class-Model Pair to the Typegoose Cache
|
86 | * This can be used to add custom Models to Typegoose, with the type information of "cl"
|
87 | * Note: no guarrantee that the type information is fully correct when used manually
|
88 | * @param model The Model to store
|
89 | * @param cl The Class to store
|
90 | * @param options Overwrite existingMongoose or existingConnection
|
91 | * @example
|
92 | * ```ts
|
93 | * class ClassName {}
|
94 | *
|
95 | * const schema = buildSchema(ClassName);
|
96 | * // modifications to the schema can be done
|
97 | * const model = addModelToTypegoose(mongoose.model("Name", schema), ClassName);
|
98 | * ```
|
99 | */
|
100 | export declare function addModelToTypegoose<U extends AnyParamConstructor<any>, QueryHelpers = BeAnObject>(model: mongoose.Model<any>, cl: U, options?: {
|
101 | existingMongoose?: mongoose.Mongoose;
|
102 | existingConnection?: any;
|
103 | disableCaching?: boolean;
|
104 | }): ReturnModelType<U, QueryHelpers>;
|
105 | /**
|
106 | * Deletes a existing model so that it can be overwritten with another model
|
107 | * (deletes from mongoose.connection and typegoose models cache and typegoose constructors cache)
|
108 | * @param name The Model's mongoose name
|
109 | * @example
|
110 | * ```ts
|
111 | * class ClassName {}
|
112 | * const NameModel = getModelForClass(ClassName);
|
113 | * deleteModel("ClassName");
|
114 | * ```
|
115 | */
|
116 | export declare function deleteModel(name: string): void;
|
117 | /**
|
118 | * Delete a model, with the given class
|
119 | * Same as "deleteModel", only that it can be done with the class instead of the name
|
120 | * @param cl The Class to delete the model from
|
121 | * @example
|
122 | * ```ts
|
123 | * class ClassName {}
|
124 | * const NameModel = getModelForClass(ClassName);
|
125 | * deleteModelWithClass(ClassName);
|
126 | * ```
|
127 | */
|
128 | export declare function deleteModelWithClass<U extends AnyParamConstructor<any>>(cl: U): void;
|
129 | /**
|
130 | * Build a Model from the given Class and add it as a discriminator onto "from"
|
131 | * @param from The Model to add the new discriminator model to
|
132 | * @param cl The Class to make a discriminator model from
|
133 | * @param options Overwrite ModelOptions (Merged with ModelOptions from class)
|
134 | * @example
|
135 | * ```ts
|
136 | * class Main {
|
137 | * @prop({ ref: () => BaseDiscriminator })
|
138 | * public discriminators?: Ref<BaseDiscriminator>;
|
139 | * }
|
140 | *
|
141 | * class BaseDiscriminator {
|
142 | * @prop()
|
143 | * public propertyOnAllDiscriminators?: string;
|
144 | * }
|
145 | *
|
146 | * class AnotherDiscriminator {
|
147 | * @prop()
|
148 | * public someValue?: string;
|
149 | * }
|
150 | *
|
151 | * const MainModel = getModelForClass(Main);
|
152 | *
|
153 | * const BaseDiscriminatorModel = getModelFroClass(BaseDiscriminator);
|
154 | * const AnotherDiscriminatorModel = getDiscriminatorModelForClass(BaseDiscriminatorModel, AnotherDiscriminator);
|
155 | * // add other discriminator models the same way as "AnotherDiscriminatorModel"
|
156 | * ```
|
157 | */
|
158 | export declare function getDiscriminatorModelForClass<U extends AnyParamConstructor<any>, QueryHelpers = BeAnObject>(from: mongoose.Model<any, any, any, any>, cl: U, options?: IModelOptions): ReturnModelType<U, QueryHelpers>;
|
159 | /**
|
160 | * Build a Model from the given Class and add it as a discriminator onto "from"
|
161 | * @param from The Model to add the new discriminator model to
|
162 | * @param cl The Class to make a discriminator model from
|
163 | * @param value The Identifier to use to differentiate documents (default: cl.name)
|
164 | * @example
|
165 | * ```ts
|
166 | * class Main {
|
167 | * @prop({ ref: () => BaseDiscriminator })
|
168 | * public discriminators?: Ref<BaseDiscriminator>;
|
169 | * }
|
170 | *
|
171 | * class BaseDiscriminator {
|
172 | * @prop()
|
173 | * public propertyOnAllDiscriminators?: string;
|
174 | * }
|
175 | *
|
176 | * class AnotherDiscriminator {
|
177 | * @prop()
|
178 | * public someValue?: string;
|
179 | * }
|
180 | *
|
181 | * const MainModel = getModelForClass(Main);
|
182 | *
|
183 | * const BaseDiscriminatorModel = getModelFroClass(BaseDiscriminator);
|
184 | * const AnotherDiscriminatorModel = getDiscriminatorModelForClass(BaseDiscriminatorModel, AnotherDiscriminator);
|
185 | * // add other discriminator models the same way as "AnotherDiscriminatorModel"
|
186 | * ```
|
187 | */
|
188 | export declare function getDiscriminatorModelForClass<U extends AnyParamConstructor<any>, QueryHelpers = BeAnObject>(from: mongoose.Model<any, any, any, any>, cl: U, value?: string): ReturnModelType<U, QueryHelpers>;
|
189 | /**
|
190 | * Build a Model from the given Class and add it as a discriminator onto "from"
|
191 | * @param from The Model to add the new discriminator model to
|
192 | * @param cl The Class to make a discriminator model from
|
193 | * @param value The Identifier to use to differentiate documents (default: cl.name)
|
194 | * @param options Overwrite ModelOptions (Merged with ModelOptions from class)
|
195 | * @example
|
196 | * ```ts
|
197 | * class Main {
|
198 | * @prop({ ref: () => BaseDiscriminator })
|
199 | * public discriminators?: Ref<BaseDiscriminator>;
|
200 | * }
|
201 | *
|
202 | * class BaseDiscriminator {
|
203 | * @prop()
|
204 | * public propertyOnAllDiscriminators?: string;
|
205 | * }
|
206 | *
|
207 | * class AnotherDiscriminator {
|
208 | * @prop()
|
209 | * public someValue?: string;
|
210 | * }
|
211 | *
|
212 | * const MainModel = getModelForClass(Main);
|
213 | *
|
214 | * const BaseDiscriminatorModel = getModelFroClass(BaseDiscriminator);
|
215 | * const AnotherDiscriminatorModel = getDiscriminatorModelForClass(BaseDiscriminatorModel, AnotherDiscriminator);
|
216 | * // add other discriminator models the same way as "AnotherDiscriminatorModel"
|
217 | * ```
|
218 | */
|
219 | export declare function getDiscriminatorModelForClass<U extends AnyParamConstructor<any>, QueryHelpers = BeAnObject>(from: mongoose.Model<any, any, any, any>, cl: U, value?: string, options?: IModelOptions): ReturnModelType<U, QueryHelpers>;
|
220 | /**
|
221 | * Use this class if raw mongoose for a path is wanted
|
222 | * It is still recommended to use the typegoose classes directly
|
223 | * @see Using `Passthrough`, the paths created will also result as an `Schema` (since mongoose 6.0), see {@link https://github.com/Automattic/mongoose/issues/7181 Mongoose#7181}
|
224 | * @example
|
225 | * ```ts
|
226 | * class Dummy {
|
227 | * @prop({ type: () => new Passthrough({ somePath: String }) })
|
228 | * public somepath: { somePath: string };
|
229 | * }
|
230 | *
|
231 | * class Dummy {
|
232 | * @prop({ type: () => new Passthrough({ somePath: String }, true) })
|
233 | * public somepath: { somePath: string };
|
234 | * }
|
235 | * ```
|
236 | */
|
237 | export declare class Passthrough {
|
238 | raw: any;
|
239 | direct: boolean;
|
240 | /**
|
241 | * Use this like `new mongoose.Schema()`
|
242 | * @param raw The Schema definition
|
243 | * @param direct Directly insert "raw", instead of using "type" (this will not apply any other inner options)
|
244 | */
|
245 | constructor(raw: any, direct?: boolean);
|
246 | }
|