Skip to content

Commit 4e407e3

Browse files
Merge pull request #276 from terminusdb/history
add history endPoint
2 parents 18846cc + 38c52ed commit 4e407e3

File tree

5 files changed

+83
-0
lines changed

5 files changed

+83
-0
lines changed

docs/api/typedef.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,3 +200,15 @@ the manage capability command type
200200
##### RolesActions: ` Array.<ACTIONS>`
201201
[ACTIONS.CREATE_DATABASE | ACTIONS.DELETE_DATABASE]
202202

203+
204+
## DocHistoryParams
205+
##### DocHistoryParams: ` Object`
206+
**Properties**
207+
208+
| Name | Type | Description |
209+
| --- | --- | --- |
210+
| [start] | <code>number</code> | Index to start from, 0 is the default |
211+
| [count] | <code>number</code> | Amount of commits to show, 10 is the default |
212+
| [updated] | <code>boolean</code> | Last updated time (excludes history) false is the default |
213+
| [created] | <code>boolean</code> | Created date of object (excludes history) false is the default |
214+

docs/api/woqlclient.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,6 +1388,29 @@ client.apply("main","mybranch","merge main").then(result=>{
13881388
})
13891389
```
13901390
1391+
## docHistory
1392+
##### woqlClient.docHistory(id, [historyParams])
1393+
Get the document's history for a specific database or branch
1394+
1395+
1396+
| Param | Type | Description |
1397+
| --- | --- | --- |
1398+
| id | <code>string</code> | id of document to report history of |
1399+
| [historyParams] | <code>typedef.DocHistoryParams</code> | |
1400+
1401+
**Example**
1402+
```javascript
1403+
//this will return the last 5 commits for the Person/Anna document
1404+
client.checkout("mybranch")
1405+
client.docHistory("Person/Anna",{start:0,count:5}).then(result=>{
1406+
console.log(result)
1407+
})
1408+
//this will return the last and the first commit for the Person/Anna document
1409+
client.docHistory("Person/Anna",{updated:true,created:true}).then(result=>{
1410+
console.log(result)
1411+
})
1412+
```
1413+
13911414
## sendCustomRequest
13921415
##### woqlClient.sendCustomRequest(requestType, customRequestURL, [payload]) ⇒ <code>Promise</code>
13931416
Call a custom Api endpoit

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)