
Security News
NIST Officially Stops Enriching Most CVEs as Vulnerability Volume Skyrockets
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.
firebase-event-store
Advanced tools
A basic multi-tenant event sourcing library using firestore to record aggregates, events, and documents (read model)
npm install firebase-event-store
const {
Aggregate,
Command,
Evento,
FirestoreEventStore,
Bus,
ERRORS
} = require('../index')
const firestoreDb = //TODO init firesore db
const evtStore = new FirestoreEventStore(firestoreDb)
const bus = new Bus(evtStore)
bus.addEventHandler(new EventCounter(docStore))
class AddNumbers extends Command {
validate(_) {
if (!_.number1) throw ERRORS.INVALID_ARGUMENTS_ERROR('number1')
if (!_.number2) throw ERRORS.INVALID_ARGUMENTS_ERROR('number2')
this.number1 = _.number1
this.number2 = _.number2
}
}
class NumbersAdded extends Evento { }
class Calculator extends Aggregate {
constructor () {
super()
this.sum = 0
}
get path () { return '/calculators' }
async handleCommand (actor, command) {
switch (command.constructor) {
case AddNumbers:
this.addEvent(actor.id, NumbersAdded, { a: command.number1, b: command.number2 })
break
}
}
applyEvent (event) {
switch (event.constructor) {
case NumbersAdded:
this.creator = event.eventCreator
this.sum += (event.a + event.b)
break
}
}
}
class EventCounter extends IEventHandler {
constructor(db) {
super()
this.db = db
}
applyEvent (actor, event, aggregate) {
const path = '/counters/counter1'
if (event.eventName === NumbersAdded.name) {
let snap = await this.db.doc(path).get()
let doc = snap.data() || {}
doc.eventCount = (doc.eventCount || 0) + 1
return await this.db.doc(path).set(doc)
}
}
}
let actor = { id: 'user1', tenant: 'tenant1' }
let calc = await bus.sendCommand(actor, Command.create(AddNumbers, { number1: 1, number2: 2 }), Calculator, 'calc1')
calc = await bus.sendCommand(actor, Command.create(AddNumbers, { number1: 3, number2: 4 }), Calculator, calc.aggregateId, calc.aggregateVersion)
console.log(calc.sum)
npm test
In lieu of a formal style guide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.
FAQs
Simple multi-tenant event sourcing store based on firestore
The npm package firebase-event-store receives a total of 1 weekly downloads. As such, firebase-event-store popularity was classified as not popular.
We found that firebase-event-store 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
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.

Security News
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.