Socket
Socket
Sign inDemoInstall

@nestjs/mongoose

Package Overview
Dependencies
Maintainers
3
Versions
62
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nestjs/mongoose - npm Package Compare versions

Comparing version 7.2.0 to 7.2.1

LICENSE

6

dist/common/mongoose.decorators.js

@@ -6,3 +6,5 @@ "use strict";

const mongoose_utils_1 = require("./mongoose.utils");
exports.InjectModel = (model) => common_1.Inject(mongoose_utils_1.getModelToken(model));
exports.InjectConnection = (name) => common_1.Inject(mongoose_utils_1.getConnectionToken(name));
const InjectModel = (model) => common_1.Inject(mongoose_utils_1.getModelToken(model));
exports.InjectModel = InjectModel;
const InjectConnection = (name) => common_1.Inject(mongoose_utils_1.getConnectionToken(name));
exports.InjectConnection = InjectConnection;

@@ -6,4 +6,5 @@ import { Type } from '@nestjs/common';

private static inspectTypeDefinition;
private static inspectRef;
private static isPrimitive;
private static isMongooseSchemaType;
}

@@ -27,2 +27,3 @@ "use strict";

const options = this.inspectTypeDefinition(item.options);
this.inspectRef(item.options);
schemaDefinition = Object.assign({ [item.propertyKey]: options }, schemaDefinition);

@@ -42,2 +43,4 @@ });

}
const isClass = /^class\s/.test(Function.prototype.toString.call(optionsOrType));
optionsOrType = isClass ? optionsOrType : optionsOrType();
const schemaDefinition = this.createForClass(optionsOrType);

@@ -61,2 +64,16 @@ const schemaMetadata = type_metadata_storage_1.TypeMetadataStorage.getSchemaMetadataByTarget(optionsOrType);

}
static inspectRef(optionsOrType) {
var _a, _b;
if (!optionsOrType || typeof optionsOrType !== 'object') {
return;
}
if (typeof (optionsOrType === null || optionsOrType === void 0 ? void 0 : optionsOrType.ref) === 'function') {
optionsOrType.ref = (_b = (_a = optionsOrType.ref()) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : optionsOrType.ref;
}
else if (Array.isArray(optionsOrType.type)) {
if (optionsOrType.type.length > 0) {
this.inspectRef(optionsOrType.type[0]);
}
}
}
static isPrimitive(type) {

@@ -63,0 +80,0 @@ return BUILT_IN_TYPES.includes(type);

import { Type } from '@nestjs/common';
import * as mongoose from 'mongoose';
export declare class SchemaFactory {
static createForClass<T = any>(target: Type<unknown>): mongoose.Schema<any>;
static createForClass<TClass extends any = any, TDocument extends mongoose.Document = TClass extends mongoose.Document ? TClass : mongoose.Document<TClass>>(target: Type<TClass>): mongoose.Schema<TDocument>;
}
{
"name": "@nestjs/mongoose",
"version": "7.2.0",
"version": "7.2.1",
"description": "Nest - modern, fast, powerful node.js web framework (@mongoose)",

@@ -25,17 +25,17 @@ "author": "Kamil Mysliwiec",

"@commitlint/config-angular": "11.0.0",
"@nestjs/common": "7.5.5",
"@nestjs/core": "7.5.5",
"@nestjs/platform-express": "7.5.5",
"@nestjs/testing": "7.5.5",
"@types/jest": "26.0.17",
"@nestjs/common": "7.6.5",
"@nestjs/core": "7.6.5",
"@nestjs/platform-express": "7.6.5",
"@nestjs/testing": "7.6.5",
"@types/jest": "26.0.19",
"@types/node": "11.15.0",
"@typescript-eslint/eslint-plugin": "4.9.1",
"@typescript-eslint/parser": "4.9.1",
"eslint": "7.15.0",
"eslint-config-prettier": "7.0.0",
"@typescript-eslint/eslint-plugin": "4.12.0",
"@typescript-eslint/parser": "4.12.0",
"eslint": "7.17.0",
"eslint-config-prettier": "7.1.0",
"eslint-plugin-import": "2.22.1",
"husky": "4.3.5",
"husky": "4.3.7",
"jest": "26.6.3",
"lint-staged": "10.5.3",
"mongoose": "5.11.5",
"mongoose": "5.11.10",
"prettier": "2.2.1",

@@ -49,3 +49,3 @@ "reflect-metadata": "0.1.13",

"ts-node": "9.1.1",
"typescript": "4.0.5"
"typescript": "4.1.3"
},

@@ -52,0 +52,0 @@ "peerDependencies": {

@@ -6,2 +6,11 @@ import * as mongoose from 'mongoose';

@Schema()
class RefClass {
@Prop()
title: string;
@Prop({ type: mongoose.Schema.Types.ObjectId, ref: () => ExampleClass })
host;
}
@Schema()
class ChildClass {

@@ -49,5 +58,13 @@ @Prop()

@Prop({
type: [{ type: mongoose.Schema.Types.ObjectId, ref: () => RefClass }],
})
ref: RefClass[];
@Prop({ required: true })
children: ChildClass;
child: ChildClass;
@Prop({ type: () => ChildClass })
child2: ChildClass;
@Prop([ChildClass])

@@ -76,2 +93,10 @@ nodes: ChildClass[];

},
ref: {
type: [
{
ref: 'RefClass',
type: mongoose.Schema.Types.ObjectId,
},
],
},
name: {

@@ -93,3 +118,3 @@ required: true,

decimal: { type: mongoose.Schema.Types.Decimal128 },
children: {
child: {
required: true,

@@ -105,2 +130,12 @@ type: {

},
child2: {
type: {
id: {
type: Number,
},
name: {
type: String,
},
},
},
any: { type: mongoose.Schema.Types.Mixed },

@@ -125,2 +160,15 @@ array: { type: [] },

it('should generate a valid schema definition (class reference) for cyclic deps', () => {
const refClassDefinition = DefinitionsFactory.createForClass(RefClass);
expect(refClassDefinition).toEqual({
host: {
ref: 'ExampleClass',
type: mongoose.Schema.Types.ObjectId,
},
title: {
type: String,
},
});
});
it('should throw an error when type is ambiguous', () => {

@@ -127,0 +175,0 @@ try {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc