![Create React App Officially Deprecated Amid React 19 Compatibility Issues](https://cdn.sanity.io/images/cgdhsj6q/production/04fa08cf844d798abc0e1a6391c129363cc7e2ab-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
mongoose-plugins-trashable
Advanced tools
A mongoose plugin that adds ablity to trash/untrash (soft deletes) model instances.
This mongoose plugin adds the ability to soft-delete model instances, optionally records the id of a model (usually a User) responsible for the action.
Also, the Model.count()
, Model.find()
, Model.findOne()
,
Model.findById()
and other static methods is augmented to show only
non-trashed instances by default. You can still retrieve trashed instances by
using new static methods Model.findTrashed()
, Model.findWithTrashed
etc.
Refer to the test cases for their usage.
Use with Caution
This plugin internally overriden the model's count()
, find()
and many
static methods to retrieve only trashed instances. It also adds a by()
to
mongoose.Query
to enable a sweet syntax to record Users responsible for the
delete action.
If you don't feel right about modifying/extending native APIs, please don't use this plugin.
This plugin is inspired by yi's plugin.
Install the module with:
npm install mongoose-plugins-trashable
var Schema = require('mongoose').Schema;
var trashable = require('mongoose-plugins-trashable');
var should = require('should');
var TrashableSchema = new Schema({});
TrashableSchema.plugin(trachsable);
Trashable = mongoose.model('Trashable', TrashableSchema);
var trashable = new TrashableModel(); // assume async
// the attributes are created with null values
trashable.should.have.property('trashedAt').that.is.null;
trashable.should.have.property('trashedBy').that.is.null;
//
// promise style
//
// trash an object
trashable.trash.exec().then(function(trashable) {
trashable.should.have.property('trashedAt').that.is.a('Date');
trashable.should.have.property('trashedBy').that.is.null;
}).done();
// trash an object, and mark the User responsible
var User = mongoose.model('User');
var user = new User({}); // assume async
trashable.trash().by(user).exec().then(function(trashable) {
trashable.should.have.property('trashedAt').that.is.a('Date');
trashable.should.have.property('trashedBy');
trashable.trashedBy.toString().should.equals(user.id);
}).done();
// restore a trashed object
trashable.restore().exec().then(function(trashable) {
trashable.should.have.property('trashedAt').that.is.null;
trashable.should.have.property('trashedBy').that.is.null;
}).done();
//
// callback style
//
// trash an object
trashable.trash(function(err, trashable) {
trashable.should.have.property('trashedAt').that.is.a('Date');
trashable.should.have.property('trashedBy').that.is.null;
});
// trash an object, and mark the User responsible
var User = mongoose.model('User');
var user = new User({}); // assume async
trashable.trash().by(user, function(err, trashable) {
trashable.should.have.property('trashedAt').that.is.a('Date');
trashable.should.have.property('trashedBy');
trashable.trashedBy.toString().should.equals(user.id);
});
// restore a trashed object
trashable.restore(function(err, trashable) {
trashable.should.have.property('trashedAt').that.is.null;
trashable.should.have.property('trashedBy').that.is.null;
});
Copyright (c) 2014 Justin Lau justin@tclau.com
Licensed under the MIT license.
FAQs
A mongoose plugin that adds ablity to trash/untrash (soft deletes) model instances.
We found that mongoose-plugins-trashable demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.