ice-db
Version:
In-memory DB
46 lines (38 loc) • 981 B
JavaScript
const uuid = require('uuid');
class Object {
/**
*Creates an instance of Object.
* @param {*} object object to create
* @memberof Object
*/
constructor(object) {
this.id = uuid()
// create a revision number
let date = new Date(Date.now()).getTime()
this.rev = `1-${date}`
// copy props
for (let prop in object) {
// NOTE: this copy mechanism does not contain any checks
// this's been made on purpose: if user have to copy id and rev, for example
this[prop] = object[prop]
}
}
/**
*Increments revisin muber per rules
*
* @memberof Object
*/
_incrementRev() {
// revision number has two parts: an iteration and a timestamp
let iteration = this.rev.split('-')[0];
// increment iteration
iteration++;
// create new timestamp
let timestamp = new Date(Date.now()).getTime()
// join two parts
this.rev = `${iteration}-${timestamp}`
}
}
module.exports = {
Object
}