@@ -543,18 +543,25 @@ WOQLClient.prototype.info = function() {
543543 * @param {WOQLQuery } woql - an instance of the WOQLQuery class
544544 * @param {string } [commitMsg] - a message describing the reason for the change that will be written into the commit log (only relevant if the query contains an update)
545545 * @param {boolean } [allWitnesses]
546+ * @param {string } [lastDataVersion] - If passed it will be used for data version tracking
547+ * @param {string } [getDataVersion] - If true it the function will return object having result and dataVersion
546548 * @returns {Promise } A promise that returns the call response object, or an Error if rejected.
547549 * @example
548550 * const result = await client.query(WOQL.star())
549551 */
550- WOQLClient . prototype . query = function ( woql , commitMsg , allWitnesses ) {
552+ WOQLClient . prototype . query = function ( woql , commitMsg , allWitnesses , lastDataVersion = '' , getDataVersion = false ) {
551553 allWitnesses = allWitnesses || false
552554 commitMsg = commitMsg || 'Commit generated with javascript client without message'
553555 if ( woql && woql . json && ( ! woql . containsUpdate ( ) || commitMsg ) ) {
554556 let doql = woql . containsUpdate ( ) ? this . generateCommitInfo ( commitMsg ) : { }
555557 doql . query = woql . json ( )
556558 if ( allWitnesses ) doql . all_witnesses = true
557- return this . dispatch ( CONST . WOQL_QUERY , this . connectionConfig . queryURL ( ) , doql )
559+
560+ if ( typeof lastDataVersion === 'string' && lastDataVersion !== '' ) {
561+ this . customHeaders ( { 'TerminusDB-Data-Version' : lastDataVersion } )
562+ }
563+
564+ return this . dispatch ( CONST . WOQL_QUERY , this . connectionConfig . queryURL ( ) , doql , getDataVersion )
558565 }
559566 let errmsg = `WOQL query parameter error`
560567 if ( woql && woql . json && woql . containsUpdate ( ) && ! commitMsg ) {
@@ -761,9 +768,10 @@ WOQLClient.prototype.clonedb = function(cloneSource, newDbId, orgId) {
761768 * @property {string } action - the action name
762769 * @property {string } apiUrl - the server call endpoint
763770 * @property {object } [payload] - the post body
771+ * @property {boolean } [getDataVersion] - If true return response with data version
764772 * @returns {Promise } A promise that returns the call response object, or an Error if rejected.
765773 */
766- WOQLClient . prototype . dispatch = function ( action , apiUrl , payload ) {
774+ WOQLClient . prototype . dispatch = function ( action , apiUrl , payload , getDataVersion ) {
767775 if ( ! apiUrl ) {
768776 return Promise . reject (
769777 new Error (
@@ -799,6 +807,7 @@ WOQLClient.prototype.dispatch = function(action, apiUrl, payload) {
799807 this . localAuth ( ) ,
800808 this . remoteAuth ( ) ,
801809 this . customHeaders ( ) ,
810+ getDataVersion ,
802811 )
803812 //}
804813
@@ -858,6 +867,8 @@ WOQLClient.prototype.updateDatabase = function(dbDoc) {
858867 * @param {typedef.DocParamsPost } [params] - the post parameters
859868 * @param {string } [dbId] - the dbid
860869 * @param {message } [string] - the insert commit message
870+ * @param {string } [lastDataVersion] If passed it will be used for data version tracking.
871+ * @param {string } [getDataVersion] If true it the function will return object having result and dataVersion.
861872 * @returns {Promise } A promise that returns the call response object, or an Error if rejected.
862873 * @example
863874 * const json = [{ "@type " : "Class",
@@ -876,14 +887,19 @@ WOQLClient.prototype.updateDatabase = function(dbDoc) {
876887 * client.addDocument(json,{"graph_type":"schema"},"mydb","add new schema")
877888 */
878889
879- WOQLClient . prototype . addDocument = function ( json , params , dbId , message = "add a new document" ) {
890+ WOQLClient . prototype . addDocument = function ( json , params , dbId , message = "add a new document" , lastDataVersion = '' , getDataVersion = false ) {
880891 if ( dbId ) {
881892 this . db ( dbId )
882893 }
894+
895+ if ( typeof lastDataVersion === 'string' && lastDataVersion !== '' ) {
896+ this . customHeaders ( { 'TerminusDB-Data-Version' : lastDataVersion } )
897+ }
898+
883899 const docParams = params || { }
884900 docParams [ 'author' ] = this . author ( )
885901 docParams [ 'message' ] = message
886- return this . dispatch ( CONST . POST , this . connectionConfig . documentURL ( docParams ) , json )
902+ return this . dispatch ( CONST . POST , this . connectionConfig . documentURL ( docParams ) , json , getDataVersion )
887903}
888904
889905/**
@@ -892,6 +908,8 @@ WOQLClient.prototype.addDocument = function(json, params, dbId, message="add a n
892908 * @param {typedef.DocParamsGet } [params] - the get parameters
893909 * @param {string } [dbId] - the database id
894910 * @param {string } [branch] - the database branch
911+ * @param {string } [lastDataVersion] If passed it will be used for data version tracking.
912+ * @param {string } [getDataVersion] If true it the function will return object having result and dataVersion.
895913 * @returns {Promise } A promise that returns the call response object, or an Error if rejected.
896914 * @example
897915 * const query = {
@@ -901,21 +919,27 @@ WOQLClient.prototype.addDocument = function(json, params, dbId, message="add a n
901919 * client.queryDocument(query,{"as_list":true})
902920 */
903921
904- WOQLClient . prototype . queryDocument = function ( query , params , dbId , branch ) {
922+ WOQLClient . prototype . queryDocument = function ( query , params , dbId , branch , lastDataVersion = '' , getDataVersion = false ) {
905923 if ( dbId ) {
906924 this . db ( dbId )
907925 }
908926 if ( branch ) {
909927 this . checkout ( branch )
910928 }
911- return this . dispatch ( CONST . QUERY_DOCUMENT , this . connectionConfig . documentURL ( params ) , query )
929+ if ( typeof lastDataVersion === 'string' && lastDataVersion !== '' ) {
930+ this . customHeaders ( { 'TerminusDB-Data-Version' : lastDataVersion } )
931+ }
932+
933+ return this . dispatch ( CONST . QUERY_DOCUMENT , this . connectionConfig . documentURL ( params ) , query , getDataVersion )
912934}
913935
914936/**
915937 *
916938 * @param {typedef.DocParamsGet } [params] - the get parameters
917939 * @param {string } [dbId] - the database id
918940 * @param {string } [branch] - the database branch
941+ * @param {string } [lastDataVersion] If passed it will be used for data version tracking.
942+ * @param {string } [getDataVersion] If true it the function will return object having result and dataVersion.
919943 * @returns {Promise } A promise that returns the call response object, or an Error if rejected.
920944 * @example
921945 * //return the schema graph as a json array
@@ -927,14 +951,17 @@ WOQLClient.prototype.queryDocument = function(query, params, dbId, branch){
927951 *
928952 */
929953//document interface
930- WOQLClient . prototype . getDocument = function ( params , dbId , branch ) {
954+ WOQLClient . prototype . getDocument = function ( params , dbId , branch , lastDataVersion = '' , getDataVersion = false ) {
931955 if ( dbId ) {
932956 this . db ( dbId )
933957 }
934958 if ( branch ) {
935959 this . checkout ( branch )
936960 }
937- return this . dispatch ( CONST . GET , this . connectionConfig . documentURL ( params ) )
961+ if ( typeof lastDataVersion === 'string' && lastDataVersion !== '' ) {
962+ this . customHeaders ( { 'TerminusDB-Data-Version' : lastDataVersion } )
963+ }
964+ return this . dispatch ( CONST . GET , this . connectionConfig . documentURL ( params ) , { } , getDataVersion )
938965}
939966
940967/**
@@ -943,30 +970,37 @@ WOQLClient.prototype.getDocument = function(params,dbId,branch){
943970 * @param {typedef.DocParamsPut } [params] - the Put parameters
944971 * @param {* } [dbId] - the database id
945972 * @param {* } [message] - the update commit message
973+ * @param {string } [lastDataVersion] If passed it will be used for data version tracking.
974+ * @param {string } [getDataVersion] If true it the function will return object having result and dataVersion.
946975 * @returns {Promise } A promise that returns the call response object, or an Error if rejected.
947976 */
948977
949- WOQLClient . prototype . updateDocument = function ( json , params , dbId , message = "update document" ) {
978+ WOQLClient . prototype . updateDocument = function ( json , params , dbId , message = "update document" , lastDataVersion = '' , getDataVersion = false ) {
950979 const docParams = params || { }
951980 docParams [ 'author' ] = this . author ( )
952981 docParams [ 'message' ] = message
953982 if ( dbId ) {
954983 this . db ( dbId )
955984 }
956- return this . dispatch ( CONST . PUT , this . connectionConfig . documentURL ( docParams ) , json )
985+ if ( typeof lastDataVersion === 'string' && lastDataVersion !== '' ) {
986+ this . customHeaders ( { 'TerminusDB-Data-Version' : lastDataVersion } )
987+ }
988+ return this . dispatch ( CONST . PUT , this . connectionConfig . documentURL ( docParams ) , json , getDataVersion )
957989}
958990
959991/**
960992 * to delete the document
961993 * @param {typedef.DocParamsDelete } [params]
962994 * @param {string } [dbId] - the database id
963995 * @param {string } [message] - the delete message
996+ * @param {string } [lastDataVersion] If passed it will be used for data version tracking
997+ * @param {string } [getDataVersion] If true it the function will return object having result and dataVersion
964998 * @returns {Promise } A promise that returns the call response object, or an Error if rejected.
965999 * @example
9661000 * client.deleteDocument({"graph_type":"schema",id:['Country','Coordinate'])
9671001 */
9681002
969- WOQLClient . prototype . deleteDocument = function ( params , dbId , message = "delete document" ) {
1003+ WOQLClient . prototype . deleteDocument = function ( params , dbId , message = "delete document" , lastDataVersion = '' , getDataVersion = false ) {
9701004 const docParams = params || { }
9711005 let payload = null
9721006 if ( Array . isArray ( params . id ) ) {
@@ -978,7 +1012,10 @@ WOQLClient.prototype.deleteDocument = function(params,dbId,message="delete docum
9781012 if ( dbId ) {
9791013 this . db ( dbId )
9801014 }
981- return this . dispatch ( CONST . DELETE , this . connectionConfig . documentURL ( docParams ) , payload )
1015+ if ( typeof lastDataVersion === 'string' && lastDataVersion !== '' ) {
1016+ this . customHeaders ( { 'TerminusDB-Data-Version' : lastDataVersion } )
1017+ }
1018+ return this . dispatch ( CONST . DELETE , this . connectionConfig . documentURL ( docParams ) , payload , getDataVersion )
9821019}
9831020/**
9841021 * The purpose of this method is to quickly discover the supported fields of a particular type.
0 commit comments