Skip to content

Commit dff54d3

Browse files
committed
adding optimize system api
1 parent 52fc7a2 commit dff54d3

File tree

3 files changed

+47
-5
lines changed

3 files changed

+47
-5
lines changed

lib/connectionConfig.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,14 @@ ConnectionConfig.prototype.squashBranchURL = function(nuid) {
386386
return b + `/branch/${nuid}`
387387
}
388388

389+
390+
/**
391+
* Generate URL for optimizing system
392+
*/
393+
ConnectionConfig.prototype.optimizeSystemUrl = function() {
394+
return `${this.apiURL()}optimize/_system`
395+
}
396+
389397
/**
390398
* Generate base db url consisting of server/action/organization/dbid
391399
*/

lib/const.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,6 @@ module.exports = Object.freeze({
4242
DELETE_CSV: 'delete_csv',
4343
MESSAGE: 'message',
4444
ACTION: 'action',
45-
INFO: 'info'
45+
INFO: 'info',
46+
OPTIMIZE_SYSTEM: 'optimize_system'
4647
})

lib/woqlClient.js

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -571,20 +571,44 @@ WOQLClient.prototype.branch = function(new_branch_id, source_free) {
571571
}
572572

573573
/**
574-
* Creates a branch starting from the current branch
574+
* Squash branch commits
575575
* @param {string} branch_id - local identifier of the new branch
576576
* @param {string} commit_msg - Textual message describing the reason for the update
577577
* @returns {Promise}
578578
*/
579-
WOQLClient.prototype.resetBranch = function(branch_id, commit_msg) {
579+
WOQLClient.prototype.squashBranch = function(branch_id, commit_msg) {
580580
if (commit_msg && branch_id) {
581581
let commit = this.generateCommitInfo(commit_msg)
582-
return this.dispatch(CONST.RESET_BRANCH, this.connectionConfig.squashBranchURL(branch_id), commit)
582+
return this.dispatch(CONST.SQUASH_BRANCH, this.connectionConfig.squashBranchURL(branch_id), commit)
583583
}
584584
let errmsg = `Branch parameter error - you must specify a valid new branch id and a commit message`
585-
return Promise.reject(new Error(ErrorMessage.getInvalidParameterMessage(CONST.BRANCH, errmsg)))
585+
return Promise.reject(new Error(ErrorMessage.getInvalidParameterMessage(CONST.SQUASH_BRANCH, errmsg)))
586586
}
587587

588+
/**
589+
* Reset branch to a commit descriptor
590+
* @param {string} branch_id - local identifier of the new branch
591+
* @param {string} commit_descriptor - a valid commit descriptor
592+
* @returns {Promise}
593+
*/
594+
WOQLClient.prototype.resetBranch = function(branch_id, commit_descriptor) {
595+
if (commit_descriptor && branch_id) {
596+
let commit = this.generateCommitDescriptor(commit_descriptor)
597+
return this.dispatch(CONST.RESET_BRANCH, this.connectionConfig.squashBranchURL(), commit)
598+
}
599+
let errmsg = `Branch parameter error - you must specify a valid new branch id and a commit message`
600+
return Promise.reject(new Error(ErrorMessage.getInvalidParameterMessage(CONST.RESET_BRANCH, errmsg)))
601+
}
602+
603+
/**
604+
* Optimize system
605+
* @returns {Promise}
606+
*/
607+
WOQLClient.prototype.optimize_system = function() {
608+
return this.dispatch(CONST.OPTIMIZE_SYSTEM, this.connectionConfig.optimizeSystemUrl())
609+
}
610+
611+
588612
/**
589613
* deletes a branch from database
590614
* @param {string} branch_id - local identifier of the branch
@@ -709,6 +733,15 @@ WOQLClient.prototype.generateCommitInfo = function(msg, author) {
709733
return ci
710734
}
711735

736+
/**
737+
* Generates the json structure for commit descriptor
738+
* @param {string} commit_descriptor - a valid commit descriptor
739+
*/
740+
WOQLClient.prototype.generateCommitDescriptor=function(commit_descriptor) {
741+
let ci = {commit_descriptor: commit_descriptor}
742+
return ci
743+
}
744+
712745
/**
713746
* Adds an author string (from the user object returned by connect) to the commit message.
714747
* @param {object} rc_args

0 commit comments

Comments
 (0)