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