{"size": 611, "ext": "js", "max_stars_repo_path": "api/models/counter.model.js", "max_stars_repo_name": "ryrudnev/dss-wm", "max_stars_repo_stars_event_min_datetime": "2016-06-10T23:18:05.000Z", "max_stars_repo_stars_event_max_datetime": "2016-06-10T23:18:05.000Z", "max_issues_repo_path": "api/models/counter.model.js", "max_issues_repo_name": "ryrudnev/dss-wm", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "api/models/counter.model.js", "max_forks_repo_name": "ryrudnev/dss-wm", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 33.9444444444, "max_line_length": 90, "alphanum_fraction": 0.6988543372}
import mongoose from 'mongoose';

const { Schema } = mongoose;

// A helpful model of uid-counter needed for generating an unique ID for entity
// (for example an axiom of ontological knowledge base generated via the stardog platform)
const CounterSchema = new Schema({
  _id: { type: String, required: true },
  seq: { type: Number, default: 0 },
});

CounterSchema.statics.genUid = function (name = 'uid') {
  return this.findByIdAndUpdate(name, { $inc: { seq: 1 } }, { upsert: true, new: true })
    .exec().then(doc => Promise.resolve(doc.seq));
};

export default mongoose.model('Counter', CounterSchema);
