Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mongoose-timestamp

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongoose-timestamp - npm Package Compare versions

Comparing version 0.5.0 to 0.6.0

test/custom_names_types_options_test.js

50

index.js

@@ -8,25 +8,35 @@ /*!

var defaults = require('defaults');
function timestampsPlugin(schema, options) {
var updatedAt = 'updatedAt';
var createdAt = 'createdAt';
var updatedAtType = Date;
var createdAtType = Date;
var updatedAtOpts = Date;
var createdAtOpts = Date;
var dataObj = {};
if (typeof options === 'object') {
if (typeof options.updatedAt === 'string') {
updatedAt = options.updatedAt;
} else if (typeof options.updatedAt === 'object') {
updatedAt = options.updatedAt.name || updatedAt;
updatedAtType = options.updatedAt.type || updatedAtType;
}
if (typeof options.createdAt === 'string') {
createdAt = options.createdAt;
} else if (typeof options.createdAt === 'object') {
createdAt = options.createdAt.name || createdAt;
createdAtType = options.createdAt.type || createdAtType;
}
if (typeof options.updatedAt === 'string') {
updatedAt = options.updatedAt;
} else if (typeof options.updatedAt === 'object') {
updatedAtOpts = defaults(options.updatedAt, {
name: updatedAt,
type: Date
});
updatedAt = updatedAtOpts.name;
}
if (typeof options.createdAt === 'string') {
createdAt = options.createdAt;
} else if (typeof options.createdAt === 'object') {
createdAtOpts = defaults(options.createdAt, {
name: createdAt,
type: Date
});
createdAt = createdAtOpts.name;
}
}
var dataObj = {};
dataObj[updatedAt] = updatedAtType;
dataObj[updatedAt] = updatedAtOpts;
if (schema.path(createdAt)) {

@@ -47,5 +57,5 @@ schema.add(dataObj);

});
} else {
dataObj[createdAt] = createdAtType;
dataObj[createdAt] = createdAtOpts;
schema.add(dataObj);

@@ -61,3 +71,3 @@ schema.pre('save', function (next) {

}
schema.pre('findOneAndUpdate', function (next) {

@@ -64,0 +74,0 @@ if (this.op === 'findOneAndUpdate') {

13

package.json
{
"name": "mongoose-timestamp",
"description": "Mongoose plugin that adds createdAt and updatedAt auto-assigned date properties",
"version": "0.5.0",
"version": "0.6.0",
"author": "Nicholas Penree <nick@penree.com>",

@@ -19,5 +19,7 @@ "keywords": [

"devDependencies": {
"mongoose": "~4.0.1",
"should": "~3.2.0",
"mocha": "~1.18.2"
"mocha": "~2.5.3",
"mongoosastic": "^4.0.2",
"mongoose": "~4.5.3",
"request": "^2.72.0",
"should": "~9.0.2"
},

@@ -30,3 +32,6 @@ "scripts": {

"node": ">= 0.6"
},
"dependencies": {
"defaults": "^1.0.3"
}
}

@@ -12,2 +12,4 @@

mongoose.Promise = global.Promise || mongoose.Promise;
mongoose = mongoose.createConnection('mongodb://localhost/mongoose_timestamps')

@@ -47,3 +49,3 @@ mongoose.on('error', function (err) {

});
it('should not have updatedAt change if parent was updated but not sub document', function(done) {

@@ -50,0 +52,0 @@ TimeCopWithSubDocs.findOne({email: 'brian@brian.com'}, function (err, found) {

Sorry, the diff of this file is not supported yet

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