UNPKG

@enonic/mock-xp

Version:

Mock Enonic XP API JavaScript Library

62 lines (61 loc) 2.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Repo = void 0; var lpad_1 = require("@enonic/js-utils/string/lpad"); var Branch_1 = require("./Branch"); var BranchAlreadyExistException_1 = require("./repo/BranchAlreadyExistException"); var BranchNotFoundException_1 = require("./repo/BranchNotFoundException"); var Repo = (function () { function Repo(_a) { var id = _a.id, server = _a.server, _b = _a.settings, settings = _b === void 0 ? {} : _b; this._highest_id = 1; this.id = id; this.server = server; this.log = this.server.log; this.settings = settings; this.branches = { 'master': new Branch_1.Branch({ branchId: 'master', repo: this }) }; } Repo.prototype.createBranch = function (branchId) { if (this.branches[branchId]) { throw new BranchAlreadyExistException_1.BranchAlreadyExistException(this.branches[branchId]); } this.branches[branchId] = new Branch_1.Branch({ branchId: branchId, repo: this }); return this.branches[branchId]; }; Repo.prototype.deleteBranch = function (branchId) { if (!this.branches[branchId]) { throw new BranchNotFoundException_1.BranchNotFoundException(branchId); } delete this.branches[branchId]; return true; }; Repo.prototype.generateId = function () { this._highest_id += 1; return "00000000-0000-4000-8000-".concat((0, lpad_1.lpad)(this._highest_id, 12, '0')); }; Repo.prototype.get = function () { return { id: this.id, branches: Object.keys(this.branches), settings: this.settings, transient: false }; }; Repo.prototype.getBranch = function (branchId) { var branchObj = this.branches[branchId]; if (!branchObj) { throw new Error("getBranch: No branch with branchId:".concat(branchId)); } return branchObj; }; return Repo; }()); exports.Repo = Repo;