Skip to content

Commit 0c1afdd

Browse files
committed
add history endPoint
1 parent 18846cc commit 0c1afdd

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

lib/connectionConfig.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,20 @@ ConnectionConfig.prototype.applyURL = function () {
540540
return purl;
541541
};
542542

543+
/**
544+
* Generate url portion consisting of organization/dbid
545+
* (unless dbid = system dbname in which case there is no organization)
546+
* @property {typedef.DocParamsPost|Object} params
547+
*/
548+
549+
ConnectionConfig.prototype.docHistoryURL = function (params) {
550+
const paramsStr = this.queryParameter(params);
551+
if (this.db() === this.system_db) {
552+
return this.dbBase('history') + paramsStr;
553+
}
554+
return this.branchBase('history') + paramsStr;
555+
};
556+
543557
/**
544558
* Generate URL for fetch endpoint
545559
* @param {string} remoteName

lib/typedef.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,4 +169,12 @@ const { ACTIONS } = Utils.ACTIONS;
169169
* @typedef {ACTIONS[]} RolesActions - [ACTIONS.CREATE_DATABASE | ACTIONS.DELETE_DATABASE]
170170
*/
171171

172+
/**
173+
* @typedef {Object} DocHistoryParams
174+
* @property {number} [start] - Index to start from, 0 is the default
175+
* @property {number} [count] - Amount of commits to show, 10 is the default
176+
* @property {boolean} [updated] - Last updated time (excludes history) false is the default
177+
* @property {boolean} [created] - Created date of object (excludes history) false is the default
178+
*/
179+
172180
module.exports = {};

lib/woqlClient.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1840,6 +1840,32 @@ WOQLClient.prototype.apply = function (beforeVersion, afterVersion, message, mat
18401840
).then((response) => response);
18411841
};
18421842

1843+
/**
1844+
* Get the document's history for a specific database or branch
1845+
* @param {string} id - id of document to report history of
1846+
* @param {typedef.DocHistoryParams} [historyParams]
1847+
* @example
1848+
* //this will return the last 5 commits for the Person/Anna document
1849+
* client.checkout("mybranch")
1850+
* client.docHistory("Person/Anna",{start:0,count:5}).then(result=>{
1851+
* console.log(result)
1852+
* })
1853+
* //this will return the last and the first commit for the Person/Anna document
1854+
* client.docHistory("Person/Anna",{updated:true,created:true}).then(result=>{
1855+
* console.log(result)
1856+
* })
1857+
*/
1858+
1859+
// eslint-disable-next-line max-len
1860+
WOQLClient.prototype.docHistory = function (id, historyParams) {
1861+
const params = historyParams || {};
1862+
params.id = id;
1863+
return this.dispatch(
1864+
CONST.GET,
1865+
this.connectionConfig.docHistoryURL(params),
1866+
).then((response) => response);
1867+
};
1868+
18431869
/**
18441870
* Call a custom Api endpoit
18451871
* @param {string} requestType - The current state of JSON document

0 commit comments

Comments
 (0)