Skip to content

Commit

Permalink
chore(): upgrade to the latest version of mongoose
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed May 20, 2022
1 parent 2466be4 commit 60f27f4
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 11,631 deletions.
7 changes: 5 additions & 2 deletions lib/factories/definitions.factory.ts
Expand Up @@ -44,7 +44,7 @@ export class DefinitionsFactory {

private static inspectTypeDefinition(
optionsOrType: mongoose.SchemaTypeOptions<unknown> | Function,
): PropOptions | [PropOptions] | Function {
): PropOptions | [PropOptions] | Function | mongoose.Schema {
if (typeof optionsOrType === 'function') {
if (this.isPrimitive(optionsOrType)) {
return optionsOrType;
Expand All @@ -69,7 +69,10 @@ export class DefinitionsFactory {
* @ref https://mongoosejs.com/docs/subdocs.html
**/

return new mongoose.Schema(schemaDefinition, schemaMetadata.options);
return new mongoose.Schema(
schemaDefinition,
schemaMetadata.options,
) as mongoose.Schema;
}
return schemaDefinition;
} else if (typeof optionsOrType.type === 'function') {
Expand Down
15 changes: 7 additions & 8 deletions lib/factories/schema.factory.ts
Expand Up @@ -5,17 +5,16 @@ import { TypeMetadataStorage } from '../storages/type-metadata.storage';
import { DefinitionsFactory } from './definitions.factory';

export class SchemaFactory {
static createForClass<
TClass extends any = any,
TDocument extends mongoose.Document = TClass extends mongoose.Document
? TClass
: mongoose.Document<TClass>,
>(target: Type<TClass>): mongoose.Schema<TDocument> {
// TODO: remove unused, deprecated type argument
// eslint-disable-next-line @typescript-eslint/no-unused-vars
static createForClass<TClass = any, _TDeprecatedTypeArgument = any>(
target: Type<TClass>,
): mongoose.Schema<TClass> {
const schemaDefinition = DefinitionsFactory.createForClass(target);
const schemaMetadata =
TypeMetadataStorage.getSchemaMetadataByTarget(target);
return new mongoose.Schema<TDocument>(
schemaDefinition as SchemaDefinition<SchemaDefinitionType<TDocument>>,
return new mongoose.Schema<TClass>(
schemaDefinition as SchemaDefinition<SchemaDefinitionType<TClass>>,
schemaMetadata && schemaMetadata.options,
);
}
Expand Down

0 comments on commit 60f27f4

Please sign in to comment.