
Security News
Feross on TBPN: How North Korea Hijacked Axios
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.
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
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
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.

Security News
OpenSSF has issued a high-severity advisory warning open source developers of an active Slack-based campaign using impersonation to deliver malware.

Research
/Security News
Malicious packages published to npm, PyPI, Go Modules, crates.io, and Packagist impersonate developer tooling to fetch staged malware, steal credentials and wallets, and enable remote access.