
Research
Two Malicious Rust Crates Impersonate Popular Logger to Steal Wallet Keys
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
mongoose-enumvalues
Advanced tools
Mongoose plugin that allows easy access to enum values. You can create virtuals, attach to your document, or modify your enum property in-place. Now with a TypeScript definition.
npm install [--save] mongoose-enumvalues
const mongoose = require('mongoose');
const enumValues = require('mongoose-enumvalues');
const { Schema } = mongoose;
const UserSchema = new Schema({
name: String,
age: Number,
role: {
type: String,
enum: ['admin', 'moderator', 'guest'],
default: 'guest'
},
gender: {
type: String,
uppercase: true,
enum: ['MALE', 'FEMALE'],
default: 'FEMALE'
},
nesting: {
enums: {
type: String,
enum: ['something', 'wicked', 'this', 'way', 'comes']
}
}
});
// specifics for each method below
const enumOptions = {};
UserSchema.plugin(enumValues, enumOptions);
module.exports = mongoose.model('User', UserSchema);
Automatically create virtual properties for enum value access.
const enumOptions = {
virtual: {
only: ['gender', 'role'],
properties: {
gender: 'genders',
role: 'roleValues'
}
}
};
//...
user.genders
=> ['MALE', 'FEMALE']
user.roleValues
=> ['admin', 'moderator', 'guest']
Simply attach enum values to your documents, restricting which paths are included,
and which methods hooked: ['find', 'findOne']
const enumOptions = {
find: true,
findOne: true,
attach: {
//only: ['gender', 'role'], if omitted, determines properties via keys
properties: {
gender: {
as: 'genderOptions',
only: ['findOne'] // restricts attaching to 'findOne' method
},
role: { // will be attached on 'find' and 'findOne'
as: 'roles'
}
}
}
};
//...
user.genderOptions
=> ['MALE', 'FEMALE']
user.roles
=> ['admin', 'moderator', 'guest']
This option directly modifies the enum property to be an object, including the original value and the array of enum options.
In order for this to work correctly, lean()
must be called.
const enumOptions = {
find: true,
findOne: true
modify: true
};
user.gender
=> {
values: ['MALE', 'FEMALE'],
value: 'MALE'
}
user.role
=> {
values: ['admin', 'moderator', 'guest'],
value: 'guest'
}
user.nesting
=> {
enums: {
values: ['something', 'wicked', 'this', 'way', 'comes'],
value: null
}
}
// You may set modified values as such
user.nesting.enums = 'wicked';
// or
user.nesting.enums.value = 'wicked';
// Alternatively you may restrict the paths and the methods
const enumOptions = {
modify: {
only: ['role'],
on: ['findOne']
}
}
Model.update
bypasses any validations and middleware. Utilizing this method with modify
will produce undesired results.
Due to the nature of Mongoose objects, modify
must be used in conjunction with lean()
.
Example: User.findOne({ username }).lean().then()...
FAQs
Mongoose plugin that provides convenient access to enum values
We found that mongoose-enumvalues 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.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
Research
A malicious package uses a QR code as steganography in an innovative technique.
Research
/Security News
Socket identified 80 fake candidates targeting engineering roles, including suspected North Korean operators, exposing the new reality of hiring as a security function.