
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
mongo-distributed-locks
Advanced tools
Node.js distributed locking based on Mongodb.
# Add to project
$ npm i mongo-distributed-locks
const DLocks = require('mongo-distributed-locks');
async function takeFee({ userId, fee }) {
let user = await User.findOne({ _id: userId });
user.balance -= fee;
return user.save();
}
function takeFeeWithLock(params) {
return DLocks.exec({
prefix: 'createPayment',
objectId: params.userId,
fn: takeFee.bind(null, params)
});
}
function doWork() {
let userId = 'some id';
return Promise.all([
takeFeeWithLock({ userId, fee: 10 }),
takeFeeWithLock({ userId, fee: 25 })
]);
}
static registerLoggerErrorFn(loggerErrorFn)
Registers logger error function (DLocks
can log a few error messages), if not provided console.error
is used`.
loggerErrorFn
- logger error function. Example of usage: DLocks.registerLoggerErrorFn(logger.error.bind(logger));
static exec({ prefix, objectId, fn })
Creates a DLocks
instance and executes its exec
method. Shortcut for let instance = new DLocks(params); instance.exec();
.
prefix
- the name of operation, createPayment, deleteUser, etc.objectId
- the id of locking object.fn
- the function that changes the locking object.exec()
Locks the resource and executes the provided function. Returns a promise.
Alexander Mac
Licensed under the MIT license.
<sub>v1.0.0</sub>
FAQs
Distributed locking based on Mongodb
The npm package mongo-distributed-locks receives a total of 1 weekly downloads. As such, mongo-distributed-locks popularity was classified as not popular.
We found that mongo-distributed-locks 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
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.