UNPKG

webgme-engine

Version:

WebGME server and Client API without a GUI

335 lines (275 loc) 12.5 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JSDoc: Source: server/storage/userproject.js</title> <script src="scripts/prettify/prettify.js"> </script> <script src="scripts/prettify/lang-css.js"> </script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> </head> <body> <div id="main"> <h1 class="page-title">Source: server/storage/userproject.js</h1> <section> <article> <pre class="prettyprint source linenums"><code>/*globals requireJS*/ /*eslint-env node*/ /** * * @module Server:UserProject * @author pmeijer / https://github.com/pmeijer */ 'use strict'; var CONSTANTS = requireJS('common/storage/constants'), generateKey = requireJS('common/util/key'), UTIL = requireJS('common/storage/util'), HELPER = require('./storagehelpers'), ProjectInterface = requireJS('common/storage/project/interface'); /** * This project is connected directly to the database and does not require the server to be running. * It is used by the bin scripts and for testing. * * @param {object} dbProject - Underlying data store project. * @param {object} storage - Safe storage. * @param {object} mainLogger - Logger instance. * @param {GmeConfig} gmeConfig * @constructor * @augments ProjectInterface */ function UserProject(dbProject, storage, mainLogger, gmeConfig) { var self = this, objectLoader = { loadObject: function (projectId, key, callback) { // dbProject.loadObject(key, callback); HELPER.loadObject(dbProject, key) .then(function (result) { callback(null, result); }) .catch(callback); }, loadPaths: function (projectId, pathsInfo, excludes, callback) { var data = { username: self.userName, projectId: projectId, pathsInfo: pathsInfo, excludes: excludes }; storage.loadPaths(data, callback); } }; ProjectInterface.call(this, dbProject.projectId, objectLoader, mainLogger, gmeConfig); this.userName = gmeConfig.authentication.guestAccount; this._dbProject = dbProject; /** * Sets the user that accesses the database. If not altered it defaults to authentication.guestAccount * in the {GmeConfig}. * @param {string} userName - User that access the database. */ this.setUser = function (userName) { this.userName = userName; }; // Helper functions this.createCommitObject = function (parents, rootHash, user, msg) { user = user || self.userName || 'n/a'; msg = msg || 'n/a'; var commitObj = { root: rootHash, parents: parents, updater: [user], time: Date.now(), message: msg, type: CONSTANTS.COMMIT_TYPE, __v: CONSTANTS.VERSION }, commitHash = '#' + generateKey(commitObj, gmeConfig); commitObj[CONSTANTS.MONGO_ID] = commitHash; return commitObj; }; // Functions defined in ProjectInterface this.makeCommit = function (branchName, parents, rootHash, coreObjects, msg, callback) { var self = this, keys = Object.keys(coreObjects), data = { username: self.userName, projectId: self.projectId, commitObject: self.createCommitObject(parents, rootHash, null, msg), coreObjects: {}, changedNodes: null }, i; for (i = 0; i &lt; keys.length; i += 1) { if (UTIL.coreObjectHasOldAndNewData(coreObjects[keys[i]])) { // Patch type object. data.coreObjects[keys[i]] = UTIL.getPatchObject(coreObjects[keys[i]].oldData, coreObjects[keys[i]].newData); } else if (coreObjects[keys[i]].newData &amp;&amp; coreObjects[keys[i]].newHash) { // A new object with no previous data (send the entire data). data.coreObjects[keys[i]] = coreObjects[keys[i]].newData; } else { // A regular object. data.coreObjects[keys[i]] = coreObjects[keys[i]]; } } data.changedNodes = UTIL.getChangedNodes(data.coreObjects, rootHash); if (branchName) { data.branchName = branchName; } return storage.makeCommit(data) .nodeify(callback); }; this.getProjectInfo = function (callback) { var data = { username: self.userName, projectId: self.projectId, branches: true, info: true, hooks: true, rights: true }; return storage.getProjects(data) .then(function (res) { return res[0]; }) .nodeify(callback); }; this.setBranchHash = function (branchName, newHash, oldHash, callback) { var data = { username: self.userName, projectId: self.projectId, branchName: branchName, newHash: newHash, oldHash: oldHash }; return storage.setBranchHash(data) .nodeify(callback); }; this.getBranchHash = function (branchName, callback) { var data = { username: self.userName, projectId: self.projectId, branchName: branchName }; return storage.getBranchHash(data) .nodeify(callback); }; this.createBranch = function (branchName, newHash, callback) { var data = { username: self.userName, projectId: self.projectId, branchName: branchName, hash: newHash }; return storage.createBranch(data) .nodeify(callback); }; this.deleteBranch = function (branchName, oldHash, callback) { var data = { username: self.userName, projectId: self.projectId, branchName: branchName, hash: oldHash }; return storage.deleteBranch(data) .nodeify(callback); }; this.getBranches = function (callback) { var data = { username: self.userName, projectId: self.projectId }; return storage.getBranches(data) .nodeify(callback); }; this.createTag = function (tagName, commitHash, callback) { var data = { username: self.userName, projectId: self.projectId, tagName: tagName, commitHash: commitHash }; return storage.createTag(data) .nodeify(callback); }; this.deleteTag = function (tagName, callback) { var data = { username: self.userName, projectId: self.projectId, tagName: tagName }; return storage.deleteTag(data) .nodeify(callback); }; this.getTags = function (callback) { var data = { username: self.userName, projectId: self.projectId }; return storage.getTags(data) .nodeify(callback); }; this.getCommits = function (before, number, callback) { var data = { username: self.userName, projectId: self.projectId, before: before, number: number }; return storage.getCommits(data) .nodeify(callback); }; this.getHistory = function (start, number, callback) { var data = { username: self.userName, projectId: self.projectId, start: start, number: number }; return storage.getHistory(data) .nodeify(callback); }; this.getCommonAncestorCommit = function (commitA, commitB, callback) { var data = { username: self.userName, projectId: self.projectId, commitA: commitA, commitB: commitB }; return storage.getCommonAncestorCommit(data) .nodeify(callback); }; this.squashCommits = function (fromCommit, toCommitOrBranch, message, callback) { var data = { username: self.userName, projectId: self.projectId, fromCommit: fromCommit, toCommitOrBranch: toCommitOrBranch, message: message }; return storage.squashCommits(data) .nodeify(callback); }; this.getUserId = function () { return this.userName; }; } UserProject.prototype = Object.create(ProjectInterface.prototype); UserProject.prototype.constructor = UserProject; module.exports = UserProject;</code></pre> </article> </section> </div> <nav> <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="Server_GMEAuth.html">Server:GMEAuth</a></li><li><a href="Server_SafeStorage.html">Server:SafeStorage</a></li><li><a href="Server_UserProject.html">Server:UserProject</a></li><li><a href="module-Core.html">Core</a></li><li><a href="module-Storage.html">Storage</a></li><li><a href="module-crosscuts.html">crosscuts</a></li><li><a href="module-serialization.html">serialization</a></li></ul><h3>Externals</h3><ul><li><a href="external-Promise.html">Promise</a></li></ul><h3>Classes</h3><ul><li><a href="AddOnBase.html">AddOnBase</a></li><li><a href="AddOnUpdateResult.html">AddOnUpdateResult</a></li><li><a href="Artifact.html">Artifact</a></li><li><a href="BlobClient.html">BlobClient</a></li><li><a href="BlobMetadata.html">BlobMetadata</a></li><li><a href="BlobRunPluginClient.html">BlobRunPluginClient</a></li><li><a href="Client.html">Client</a></li><li><a href="Core.html">Core</a></li><li><a href="ExecutorClient.html">ExecutorClient</a></li><li><a href="GMENode.html">GMENode</a></li><li><a href="GmeLogger.html">GmeLogger</a></li><li><a href="InterPluginResult.html">InterPluginResult</a></li><li><a href="JobInfo.html">JobInfo</a></li><li><a href="OutputInfo.html">OutputInfo</a></li><li><a href="PluginBase.html">PluginBase</a></li><li><a href="PluginConfig.html">PluginConfig</a></li><li><a href="PluginMessage.html">PluginMessage</a></li><li><a href="PluginNodeDescription.html">PluginNodeDescription</a></li><li><a href="PluginResult.html">PluginResult</a></li><li><a href="Project.html">Project</a></li><li><a href="ProjectInterface.html">ProjectInterface</a></li><li><a href="Server_GMEAuth-GMEAuth.html">GMEAuth</a></li><li><a href="Server_SafeStorage-SafeStorage.html">SafeStorage</a></li><li><a href="Server_UserProject-UserProject.html">UserProject</a></li><li><a href="WebsocketRouter.html">WebsocketRouter</a></li><li><a href="WebsocketRouterUser.html">WebsocketRouterUser</a></li></ul><h3>Events</h3><ul><li><a href="Client.html#event:BRANCH_CHANGED">BRANCH_CHANGED</a></li><li><a href="Client.html#event:BRANCH_CLOSED">BRANCH_CLOSED</a></li><li><a href="Client.html#event:BRANCH_OPENED">BRANCH_OPENED</a></li><li><a href="Client.html#event:BRANCH_STATUS_CHANGED">BRANCH_STATUS_CHANGED</a></li><li><a href="Client.html#event:CONNECTED_USERS_CHANGED">CONNECTED_USERS_CHANGED</a></li><li><a href="Client.html#event:NETWORK_STATUS_CHANGED">NETWORK_STATUS_CHANGED</a></li><li><a href="Client.html#event:NOTIFICATION">NOTIFICATION</a></li><li><a href="Client.html#event:PLUGIN_FINISHED">PLUGIN_FINISHED</a></li><li><a href="Client.html#event:PLUGIN_INITIATED">PLUGIN_INITIATED</a></li><li><a href="Client.html#event:PLUGIN_NOTIFICATION">PLUGIN_NOTIFICATION</a></li><li><a href="Client.html#event:PROJECT_CLOSED">PROJECT_CLOSED</a></li><li><a href="Client.html#event:PROJECT_OPENED">PROJECT_OPENED</a></li></ul><h3><a href="global.html">Global</a></h3> </nav> <br class="clear"> <footer> Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Fri Jun 21 2024 09:43:40 GMT-0400 (Eastern Daylight Time) </footer> <script> prettyPrint(); </script> <script src="scripts/linenumber.js"> </script> </body> </html>