55from marklogic .documents import DocumentManager
66from marklogic .internal .eval import process_multipart_mixed_response
77from marklogic .rows import RowManager
8- from marklogic .transactions import TransactionManager
8+ from marklogic .transactions import TransactionManager , Transaction
99from requests .auth import HTTPDigestAuth
1010from urllib .parse import urljoin
1111
@@ -93,6 +93,7 @@ def eval(
9393 javascript : str = None ,
9494 xquery : str = None ,
9595 vars : dict = None ,
96+ tx : Transaction = None ,
9697 return_response : bool = False ,
9798 ** kwargs ,
9899 ):
@@ -104,6 +105,7 @@ def eval(
104105 :param javascript: a JavaScript script
105106 :param xquery: an XQuery script
106107 :param vars: a dict containing variables to include
108+ :param tx: optional REST transaction in which to service this request.
107109 :param return_response: boolean specifying if the entire original response
108110 object should be returned (True) or if only the data should be returned (False)
109111 upon a success (2xx) response. Note that if the status code of the response is
@@ -118,15 +120,23 @@ def eval(
118120 raise ValueError ("Must define either 'javascript' or 'xquery' argument." )
119121 if vars :
120122 data ["vars" ] = json .dumps (vars )
121- response = self .post ("v1/eval" , data = data , ** kwargs )
123+ params = kwargs .pop ("params" , {})
124+ if tx :
125+ params ["txid" ] = tx .id
126+ response = self .post ("v1/eval" , data = data , params = params , ** kwargs )
122127 return (
123128 process_multipart_mixed_response (response )
124129 if response .status_code == 200 and not return_response
125130 else response
126131 )
127132
128133 def invoke (
129- self , module : str , vars : dict = None , return_response : bool = False , ** kwargs
134+ self ,
135+ module : str ,
136+ vars : dict = None ,
137+ tx : Transaction = None ,
138+ return_response : bool = False ,
139+ ** kwargs ,
130140 ):
131141 """
132142 Send a script (XQuery or JavaScript) and possibly a dict of vars
@@ -135,6 +145,7 @@ def invoke(
135145
136146 :param module: The URI of a module in the modules database of the app server
137147 :param vars: a dict containing variables to include
148+ :param tx: optional REST transaction in which to service this request.
138149 :param return_response: boolean specifying if the entire original response
139150 object should be returned (True) or if only the data should be returned (False)
140151 upon a success (2xx) response. Note that if the status code of the response is
@@ -143,7 +154,10 @@ def invoke(
143154 data = {"module" : module }
144155 if vars :
145156 data ["vars" ] = json .dumps (vars )
146- response = self .post ("v1/invoke" , data = data , ** kwargs )
157+ params = kwargs .pop ("params" , {})
158+ if tx :
159+ params ["txid" ] = tx .id
160+ response = self .post ("v1/invoke" , data = data , params = params , ** kwargs )
147161 return (
148162 process_multipart_mixed_response (response )
149163 if response .status_code == 200 and not return_response
0 commit comments