npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

eventstore-objectmapper

v1.1.1

Published

objectmapper for eventstore module

Downloads

3

Readme

Eventstore Object Mapper

This maps events to specific objects in an orm like fashon

npm i eventstore-objectmapper

Required Dependencies

Need Node 8 for async await syntax

Also, uses the eventstore module. One must know how to set this up to use this module. https://www.npmjs.com/package/eventstore

npm i eventstore

Doc Menu

  1. Getting Started
  2. Example Model
  3. Instance Properties
    1. dataValues
    2. latestDataValues
    3. selectedRevision
    4. latestRevision
    5. primaryValue
    6. getHistory
  4. Instance Methods
    1. saveData
    2. saveWhole
    3. takeSnapshot
    4. saveCurrentValues
    5. goToRevision
    6. goToLatestRevision
  5. Static Methods
    1. create
    2. findById
    3. createOrFind
    4. createOrUpdate
    5. findOneAndUpdate
    6. getHistory
  6. Static Getters
    1. schema
    2. snapshotFrequency

Getting Started

make a directory called models, or eventmodels.

const eventstore = require('eventstore');
const {Model} = require('eventstore-objectmapper');

let es = eventstore();

Model.init(es).then(()=>{
    //ready to use
}

Example Model

make file called user.js in models directory

const {Model} = require('eventstore-objectmapper');

class User extends Model {
    constructor(id){
        super(id);
    }

    static get schema(){
        return {
            id:{type:"Number", primary:true}
        }
    }
}

module.exports = User;

Instance Properties

dataValues

let user = await User.create({id:1, first:'Brian', last:'Alois'});

console.log('output:', user.dataValues);

//output: {id:1, first:'Brian', last:'Alois'}

latestDataValues

let user = await User.create({id:1, first:'Brian', last:'Alois'});

await user.saveData({first:'John'});

await user.goToRevision(0);

console.log('selected revision: ', user.dataValues, '\n, latest: ',user.latestDataValues)
//selected revision:  {id:1, first:'Brian', last:'Alois'}, 
//latest: {id:1, first:'John', last:'Alois'}

Instance Methods

saveData

The saveData method adds and updates data with what is given.

const User = require('./models/user');

let user = await User.create({id:1, first:'Brian', last:'Alois'});

await user.saveData({info:'software', last:null});

console.log(user.dataValues);
//{id:1, first:'Brian', last:null, info:'software'}

saveWhole

This is a little different from saveData in that the most updated revision becomes entirely the input

const User = require('./models/user');

let user = await User.create({id:1, first:'Brian', last:'Alois'});

await user.saveWhole({id: 1, info:'software'});

console.log(user.dataValues);
//{id: 1, first:null, last: null, info:'software'}

takeSnapshot

takes snapshot of latest values that were saved.

await user.takeSnapshot();

goToRevision

await user = await User.create({id:1, first:'brian', last:'alois'});
console.log(user.selectedRevision, user.first);
//0 brian

await user.saveData({first:'John'});
console.log(user.selectedRevision, user.first);
//1 John

await user.goToRevision(0);
console.log(user.selectedRevision, user.first);
//0 brian

getHistory

returns history of all the events of the instance

let history = await user.getHistory();

Static Methods

create

const User = require('./models/user');

let user = await User.create({id:1, firstName:'Brian', lastName:' Doe});

findById

const User = require('./models/user');

let user = await User.findById(1);

createOrFind

Method either finds and returns instance or creates it if it doesn't exist

const User = require('./models/user');

let user = await User.createOrFind({id:1, firstName:'Brian'});

createOrUpdate

Method either updates existing instance based on primary key, or if one does not exist with that primary it creates it

const User = require('./models/user');

let user = await User.createOrUpdate({id:1, firstName:'Brian'});

findOneAndUpdate

finds one based on primary value, in this case is id, and updates it.

let user = await User.findOneAndUpdate({id:1, firstName:'Brian'});

if upsert option is set to true it will create it if it is not found

let user = await User.findOneAndUpdate({id:1, firstName:'Brian'}, {upsert:true});

the defualt update is a saveData. If you want to do a saveWhole pass in the option whole=true

let user = await User.findOneAndUpdate({id:1, firstName:'Brian'}, {upsert:true, whole:true});

getHistory

get all the events and dates that events were added

let user_id = 2
let history = await User.getHisory(user_id);

Static Getters

schema

This is necessary, particularly the part where there is a key that is primary;

class User extends Model {
    constructor(id){
        super(id);
    }

    static get schema(){
        return {
            id:{type:"Number", primary:true},
            name:{type:"String"}
        }
    }
}

snapshotFrequency

by defualt it is set to take a snapshot at every 25 events, or saves/changes to the data. However, this can be changed.

class User extends Model {
    constructor(id){
        super(id);
    }

    static get schema(){
        return {
            id:{type:"Number", primary:true},
            name:{type:"String"}
        }
    }
    
    static get snapshotFrequency(){
        return 10;
    }
}