Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
A store that sits on top of your DAO to save your application from making unecessary calls.
This module has zero dependecies.
This module is compatible with Browsers.
npm install astore --save
When communicating with data services or databases, it is very common to include some form of caching layer in front of it. Unfortunatly, cache hit rates are not always optimal. Some resources run very hot and could even be requested multiple times concurrently.
This module is a light wrapper for your data-access object. Provided it's methods accept a single option parameter and return Promises. astore
will make sure that no two same requests are made simultaneously.
DAO Example:
function getUser(options) {
// Make some db call
return new Promise((resolve, reject) => {
db.execute('SELECT * from users WHERE id = ?', [options.id], (rows) => {
if (!rows || !rows.length) return reject();
resolve(rows[0]);
});
});
}
//...
You'll need to wrap your dao object and make sure that the signature for calls include an identifier at the top level of the options parameters and in the output.
const astore = require("astore");
const usersDAO = require("../dao/users");
const usersStore = astore(usersDAO, {
timeoutStep: 1000, // Subsequent requests for the same entity will extend the caching for <timeoutStep> ms.
maxTimeout: 10000, // This is the maximum caching period for a given entity in ms.
identifier: "id", // If the identifier portion of your entity is not labeled "id", you can define it here.
storageKey: (id, opts) => `${opts.category}.${id}` // The method for assigning unique keys for store entries.
});
/**
* Get a single entity
* The first argument represents the arguments that you would normally pass to your DAO.
* The second is the DOA method to call. Make sure that the reply from the DAO is a single cacheable entity.
*/
usersStore.get({ id: 123 }, "getUser")
.then((user) => /* The user */);
/**
* Get a list of entities
* This leverages pre-flight store optimizations by running the actual DAO calls individually.
* Otherwise, you could use the post-call caching provided with the `search` function.
*/
userStore.getList({ ids: [123, 456, 789] }, "getUser")
.then((users) => /* The list of users */);
userStore.search({ ids: [123, 456, 789] }, "getList")
.then((users) => /* The list of users */);
/**
* Skip store features
* For any sensitive or user-specific data, it is NOT recommended to use storing.
* To bypass the store, you can use the `direct` method.
*/
userStore.list({ ids: [123, 456, 789] }, "getUser")
.then((users) => /* The list of users */);
The promise handle as well as the response value will be cached for some time. This is configurable via the timeoutStep value. If other queries are made for that specific identifier, the caching period is extended by the timeoutStep, up to maxTimeout.
The search method first makes the call, then caches the individual entities with the same rules as a single get. You can therefore wrap search methods or list methods alike.
npm test
Pull requests are always welcome! Please follow a few guidelines:
Add a unit test or two to cover the proposed changes Do as the Romans do and stick with existing whitespace and formatting conventions (i.e., spaces instead of tabs, etc) Please note that all interactions with Shutterstock follow the Contributor Covenant Code of Conduct.
Make sure that you also follow the Contributing Guidelines.
MIT (c) 2017 Shutterstock
FAQs
An ephemeral shared store for DAOs
The npm package astore receives a total of 1 weekly downloads. As such, astore popularity was classified as not popular.
We found that astore 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
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.