viewmodel
Advanced tools
Comparing version 1.10.11 to 1.11.0
@@ -127,3 +127,7 @@ var tolerate = require('tolerance'), | ||
vm.set('commitStamp', (new Date()).getTime()); | ||
orgCommit.apply(this, [vm, callback]); | ||
repo.emit('before-database-commit', Date.now(), vm); | ||
orgCommit.apply(this, [vm, function (err, res) { | ||
repo.emit('after-database-commit', Date.now(), vm); | ||
if (callback) callback(err, res); | ||
}]); | ||
}; | ||
@@ -141,3 +145,5 @@ var orgFind = repo.find; | ||
} | ||
repo.emit('before-database-find', Date.now(), query, queryOptions); | ||
orgFind.apply(this, [query, queryOptions, function (err, res) { | ||
repo.emit('after-database-find', Date.now(), query, queryOptions); | ||
if (err) { | ||
@@ -170,4 +176,21 @@ return callback(err); | ||
} | ||
orgFindOne.apply(this, [query, queryOptions, callback]); | ||
repo.emit('before-database-findOne', Date.now(), query, queryOptions); | ||
orgFindOne.apply(this, [query, queryOptions, function (err, res) { | ||
repo.emit('after-database-findOne', Date.now(), query, queryOptions); | ||
if (callback) callback(err, res); | ||
}]); | ||
}; | ||
var orgGet = repo.get; | ||
repo.get = function (id, callback) { | ||
if (typeof id === 'function') { | ||
callback = id; | ||
id = null; | ||
} | ||
repo.emit('before-database-get', Date.now(), id); | ||
orgGet.apply(this, [id, function (err, res) { | ||
repo.emit('after-database-get', Date.now(), id); | ||
if (callback) callback(err, res); | ||
}]); | ||
}; | ||
// Do not modify anything... it's write and we can do everything!!! | ||
@@ -206,3 +229,5 @@ connect(repo, options, callback); | ||
} | ||
repo.emit('before-database-get', Date.now(), id); | ||
orgGet.apply(this, [id, function (err, res) { | ||
repo.emit('after-database-get', Date.now(), id); | ||
if (err) { | ||
@@ -232,3 +257,5 @@ return callback(err); | ||
} | ||
repo.emit('before-database-find', Date.now(), query, queryOptions); | ||
orgFind.apply(this, [query, queryOptions, function (err, res) { | ||
repo.emit('after-database-find', Date.now(), query, queryOptions); | ||
if (err) { | ||
@@ -265,3 +292,5 @@ return callback(err); | ||
} | ||
repo.emit('before-database-findOne', Date.now(), query, queryOptions); | ||
orgFindOne.apply(this, [query, queryOptions, function (err, res) { | ||
repo.emit('after-database-findOne', Date.now(), query, queryOptions); | ||
if (err) { | ||
@@ -268,0 +297,0 @@ return callback(err); |
{ | ||
"author": "adrai", | ||
"name": "viewmodel", | ||
"version": "1.10.11", | ||
"version": "1.11.0", | ||
"private": false, | ||
@@ -17,7 +17,7 @@ "main": "index.js", | ||
"jsondate": "0.0.1", | ||
"lodash": "4.17.10", | ||
"lodash": "4.17.11", | ||
"parent-require": "1.0.0", | ||
"sift": "5.0.0", | ||
"tolerance": "1.0.0", | ||
"uuid": "3.1.0" | ||
"uuid": "3.3.2" | ||
}, | ||
@@ -24,0 +24,0 @@ "devDependencies": { |
@@ -194,3 +194,15 @@ # Introduction | ||
## Catch before and after database events | ||
var repository = viewmodel.write({ type: 'mongodb' }); | ||
repository.on('before-database-get', function(ms, id) { console.log(ms, id); }); | ||
repository.on('after-database-get', function(ms, id) { console.log(ms, id); }); | ||
repository.on('before-database-find', function(ms, query, queryOptions) { console.log(ms, query, queryOptions); }); | ||
repository.on('after-database-find', function(ms, query, queryOptions) { console.log(ms, query, queryOptions); }); | ||
repository.on('before-database-findOne', function(ms, query, queryOptions) { console.log(ms, query, queryOptions); }); | ||
repository.on('after-database-findOne', function(ms, query, queryOptions) { console.log(ms, query, queryOptions); }); | ||
repository.on('before-database-commit', function(ms, vm) { console.log(ms, vm); }); | ||
repository.on('after-database-commit', function(ms, vm) { console.log(ms, vm); }); | ||
# Implementation differences | ||
@@ -339,3 +351,3 @@ | ||
Copyright (c) 2018 Adriano Raiano | ||
Copyright (c) 2019 Adriano Raiano | ||
@@ -342,0 +354,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy |
@@ -0,1 +1,4 @@ | ||
## [v1.11.0](https://github.com/adrai/node-viewmodel/compare/v1.10.11...v1.11.0) | ||
- introduce before and after database events | ||
## [v1.10.11](https://github.com/adrai/node-viewmodel/compare/v1.10.10...v1.10.11) | ||
@@ -2,0 +5,0 @@ - Fix options indexes [#68](https://github.com/adrai/node-viewmodel/pull/68) thanks to [tommiii](https://github.com/tommiii) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
147700
3892
369
0
+ Addedlodash@4.17.11(transitive)
+ Addeduuid@3.3.2(transitive)
- Removedlodash@4.17.10(transitive)
- Removeduuid@3.1.0(transitive)
Updatedlodash@4.17.11
Updateduuid@3.3.2