
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
@aeinbu/eventstore
Advanced tools
A simple filebased eventsourced data store for node.js.
Instead of storing the current state of our data, eventsourcing lets us record our intention while creating/manipulating our data.
npm install @aeinbu/eventstore
Example of an object to be stored with this eventstore:
// contactlist.js
function ContactList(dispatch, configureStore){
let contacts = {}; // This is where the actual data is stored
// These are the eventhandlers, that manipulate the data.
configureStore({
eventhandlers:{
onContactAdded(eventdata){
if(!contacts[eventdata.contact.name])
{
contacts[eventdata.contact.name] = eventdata.contact;
return;
}
throw new Error("Contact already exists");
},
onContactRemoved(eventdata){
if(contacts[eventdata.contactname])
{
delete contacts[eventdata.contactname];
return;
}
throw new Error("Contact doesnt exist");
}
}
});
// These are the command methods that are exposed to the developer using this class
this.addContact = (contact) => {
dispatch("contactAdded", {contact});
};
this.removeContact = (contactname) => {
dispatch("contactRemoved", {contactname});
};
// This is a query method that is exposed to the developer using this class
this.getAllContacts = () => {
return Object.keys(contacts).map(key => contacts[key]);
};
}
Usage of contactlist
with the eventstore:
// demo.js
const defineStore = require("@aeinbu/eventstore");
const Contactlist = require("./ContactList");
(async funtion(){
const folder = "path/to/store";
const createContactlistFn = (dispatch, configureStore) => new Contactlist(dispatch, configureStore);
let store = await defineStore(folder);
let rw = store.defineReadWriteModel("rw", createContactlistFn);
rw.withRetries((contactlist, readyToCommit) => {
contactlist.addContact({name: "Mickey Mouse", city: "Duckburgh", species: "Mouse"});
contactlist.addContact({name: "Goofey", city: "Duckburgh", species: "Dog"});
readyToCommit();
}); // Everything is saved to log at end of block.
rw.withRetries((contactlist, readyToCommit) => {
contactlist.addContact({name: "Peter Pan", city: "Never Never Land", species: "Boy"});
contactlist.removeContact("Goofey");
}); // Nothing is saved to log. This unit of work was rolled back because no call was made to readyToCommit().
})();
See the tests/
folder for a more complete example, including support for snapshots, multiple models, including read-only models
let storeBase = defineStore(folder)
- Sets up a folder as a database. Is the base for creating models on that folder.
storeBase.defineReadModel(action)
-
storeBase.defineWriteModel(action)
-
storeBase.defineReadWriteModel(action, commitCallback)
-
FAQs
A simple filebased eventsourced store
We found that @aeinbu/eventstore 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
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.