@@ -543,18 +543,25 @@ WOQLClient.prototype.info = function() {
543
543
* @param {WOQLQuery } woql - an instance of the WOQLQuery class
544
544
* @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)
545
545
* @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
546
548
* @returns {Promise } A promise that returns the call response object, or an Error if rejected.
547
549
* @example
548
550
* const result = await client.query(WOQL.star())
549
551
*/
550
- WOQLClient . prototype . query = function ( woql , commitMsg , allWitnesses ) {
552
+ WOQLClient . prototype . query = function ( woql , commitMsg , allWitnesses , lastDataVersion = '' , getDataVersion = false ) {
551
553
allWitnesses = allWitnesses || false
552
554
commitMsg = commitMsg || 'Commit generated with javascript client without message'
553
555
if ( woql && woql . json && ( ! woql . containsUpdate ( ) || commitMsg ) ) {
554
556
let doql = woql . containsUpdate ( ) ? this . generateCommitInfo ( commitMsg ) : { }
555
557
doql . query = woql . json ( )
556
558
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 )
558
565
}
559
566
let errmsg = `WOQL query parameter error`
560
567
if ( woql && woql . json && woql . containsUpdate ( ) && ! commitMsg ) {
@@ -761,9 +768,10 @@ WOQLClient.prototype.clonedb = function(cloneSource, newDbId, orgId) {
761
768
* @property {string } action - the action name
762
769
* @property {string } apiUrl - the server call endpoint
763
770
* @property {object } [payload] - the post body
771
+ * @property {boolean } [getDataVersion] - If true return response with data version
764
772
* @returns {Promise } A promise that returns the call response object, or an Error if rejected.
765
773
*/
766
- WOQLClient . prototype . dispatch = function ( action , apiUrl , payload ) {
774
+ WOQLClient . prototype . dispatch = function ( action , apiUrl , payload , getDataVersion ) {
767
775
if ( ! apiUrl ) {
768
776
return Promise . reject (
769
777
new Error (
@@ -799,6 +807,7 @@ WOQLClient.prototype.dispatch = function(action, apiUrl, payload) {
799
807
this . localAuth ( ) ,
800
808
this . remoteAuth ( ) ,
801
809
this . customHeaders ( ) ,
810
+ getDataVersion ,
802
811
)
803
812
//}
804
813
@@ -858,6 +867,8 @@ WOQLClient.prototype.updateDatabase = function(dbDoc) {
858
867
* @param {typedef.DocParamsPost } [params] - the post parameters
859
868
* @param {string } [dbId] - the dbid
860
869
* @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.
861
872
* @returns {Promise } A promise that returns the call response object, or an Error if rejected.
862
873
* @example
863
874
* const json = [{ "@type " : "Class",
@@ -876,14 +887,19 @@ WOQLClient.prototype.updateDatabase = function(dbDoc) {
876
887
* client.addDocument(json,{"graph_type":"schema"},"mydb","add new schema")
877
888
*/
878
889
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 ) {
880
891
if ( dbId ) {
881
892
this . db ( dbId )
882
893
}
894
+
895
+ if ( typeof lastDataVersion === 'string' && lastDataVersion !== '' ) {
896
+ this . customHeaders ( { 'TerminusDB-Data-Version' : lastDataVersion } )
897
+ }
898
+
883
899
const docParams = params || { }
884
900
docParams [ 'author' ] = this . author ( )
885
901
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 )
887
903
}
888
904
889
905
/**
@@ -892,6 +908,8 @@ WOQLClient.prototype.addDocument = function(json, params, dbId, message="add a n
892
908
* @param {typedef.DocParamsGet } [params] - the get parameters
893
909
* @param {string } [dbId] - the database id
894
910
* @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.
895
913
* @returns {Promise } A promise that returns the call response object, or an Error if rejected.
896
914
* @example
897
915
* const query = {
@@ -901,21 +919,27 @@ WOQLClient.prototype.addDocument = function(json, params, dbId, message="add a n
901
919
* client.queryDocument(query,{"as_list":true})
902
920
*/
903
921
904
- WOQLClient . prototype . queryDocument = function ( query , params , dbId , branch ) {
922
+ WOQLClient . prototype . queryDocument = function ( query , params , dbId , branch , lastDataVersion = '' , getDataVersion = false ) {
905
923
if ( dbId ) {
906
924
this . db ( dbId )
907
925
}
908
926
if ( branch ) {
909
927
this . checkout ( branch )
910
928
}
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 )
912
934
}
913
935
914
936
/**
915
937
*
916
938
* @param {typedef.DocParamsGet } [params] - the get parameters
917
939
* @param {string } [dbId] - the database id
918
940
* @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.
919
943
* @returns {Promise } A promise that returns the call response object, or an Error if rejected.
920
944
* @example
921
945
* //return the schema graph as a json array
@@ -927,14 +951,17 @@ WOQLClient.prototype.queryDocument = function(query, params, dbId, branch){
927
951
*
928
952
*/
929
953
//document interface
930
- WOQLClient . prototype . getDocument = function ( params , dbId , branch ) {
954
+ WOQLClient . prototype . getDocument = function ( params , dbId , branch , lastDataVersion = '' , getDataVersion = false ) {
931
955
if ( dbId ) {
932
956
this . db ( dbId )
933
957
}
934
958
if ( branch ) {
935
959
this . checkout ( branch )
936
960
}
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 )
938
965
}
939
966
940
967
/**
@@ -943,30 +970,37 @@ WOQLClient.prototype.getDocument = function(params,dbId,branch){
943
970
* @param {typedef.DocParamsPut } [params] - the Put parameters
944
971
* @param {* } [dbId] - the database id
945
972
* @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.
946
975
* @returns {Promise } A promise that returns the call response object, or an Error if rejected.
947
976
*/
948
977
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 ) {
950
979
const docParams = params || { }
951
980
docParams [ 'author' ] = this . author ( )
952
981
docParams [ 'message' ] = message
953
982
if ( dbId ) {
954
983
this . db ( dbId )
955
984
}
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 )
957
989
}
958
990
959
991
/**
960
992
* to delete the document
961
993
* @param {typedef.DocParamsDelete } [params]
962
994
* @param {string } [dbId] - the database id
963
995
* @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
964
998
* @returns {Promise } A promise that returns the call response object, or an Error if rejected.
965
999
* @example
966
1000
* client.deleteDocument({"graph_type":"schema",id:['Country','Coordinate'])
967
1001
*/
968
1002
969
- WOQLClient . prototype . deleteDocument = function ( params , dbId , message = "delete document" ) {
1003
+ WOQLClient . prototype . deleteDocument = function ( params , dbId , message = "delete document" , lastDataVersion = '' , getDataVersion = false ) {
970
1004
const docParams = params || { }
971
1005
let payload = null
972
1006
if ( Array . isArray ( params . id ) ) {
@@ -978,7 +1012,10 @@ WOQLClient.prototype.deleteDocument = function(params,dbId,message="delete docum
978
1012
if ( dbId ) {
979
1013
this . db ( dbId )
980
1014
}
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 )
982
1019
}
983
1020
/**
984
1021
* The purpose of this method is to quickly discover the supported fields of a particular type.
0 commit comments