@@ -7,25 +7,36 @@ use common::{
77 AllowedVisibility ,
88 FunctionCaller ,
99 } ,
10- value:: ConvexValue ,
1110 RequestId ,
1211} ;
1312use model:: session_requests:: types:: SessionRequestIdentifier ;
1413use serde_json:: Value as JsonValue ;
15- use sync_types:: AuthenticationToken ;
14+ use sync_types:: {
15+ AuthenticationToken ,
16+ SerializedQueryJournal ,
17+ Timestamp ,
18+ } ;
1619
1720use crate :: {
18- redaction:: {
19- RedactedJsError ,
20- RedactedLogLines ,
21- } ,
2221 Application ,
2322 RedactedActionError ,
2423 RedactedActionReturn ,
2524 RedactedMutationError ,
2625 RedactedMutationReturn ,
26+ RedactedQueryReturn ,
2727} ;
2828
29+ #[ cfg_attr(
30+ any( test, feature = "testing" ) ,
31+ derive( proptest_derive:: Arbitrary , Debug , Clone , PartialEq )
32+ ) ]
33+ pub enum ExecuteQueryTimestamp {
34+ // Execute the query at the latest timestamp.
35+ Latest ,
36+ // Execute the query at a given timestamp.
37+ At ( Timestamp ) ,
38+ }
39+
2940// A trait that abstracts the backend API. It all state and validation logic
3041// so http routes can be kept thin and stateless. The implementor is also
3142// responsible for routing the request to the appropriate backend in the hosted
@@ -40,8 +51,9 @@ pub trait ApplicationApi: Send + Sync {
4051 path : ComponentFunctionPath ,
4152 args : Vec < JsonValue > ,
4253 caller : FunctionCaller ,
43- // TODO(presley): Replace this with RedactedQueryReturn.
44- ) -> anyhow:: Result < ( Result < ConvexValue , RedactedJsError > , RedactedLogLines ) > ;
54+ ts : ExecuteQueryTimestamp ,
55+ journal : Option < SerializedQueryJournal > ,
56+ ) -> anyhow:: Result < RedactedQueryReturn > ;
4557
4658 async fn execute_public_mutation (
4759 & self ,
@@ -77,7 +89,9 @@ impl<RT: Runtime> ApplicationApi for Application<RT> {
7789 path : ComponentFunctionPath ,
7890 args : Vec < JsonValue > ,
7991 caller : FunctionCaller ,
80- ) -> anyhow:: Result < ( Result < ConvexValue , RedactedJsError > , RedactedLogLines ) > {
92+ ts : ExecuteQueryTimestamp ,
93+ journal : Option < SerializedQueryJournal > ,
94+ ) -> anyhow:: Result < RedactedQueryReturn > {
8195 anyhow:: ensure!(
8296 caller. allowed_visibility( ) == AllowedVisibility :: PublicOnly ,
8397 "This method should not be used by internal callers."
@@ -86,14 +100,12 @@ impl<RT: Runtime> ApplicationApi for Application<RT> {
86100 let validate_time = self . runtime ( ) . system_time ( ) ;
87101 let identity = self . authenticate ( auth_token, validate_time) . await ?;
88102
89- let ts = * self . now_ts_for_reads ( ) ;
90- let journal = None ;
91-
92- let query_return = self
93- . read_only_udf_at_ts ( request_id, path, args, identity, ts, journal, caller)
94- . await ?;
95-
96- Ok ( ( query_return. result , query_return. log_lines ) )
103+ let ts = match ts {
104+ ExecuteQueryTimestamp :: Latest => * self . now_ts_for_reads ( ) ,
105+ ExecuteQueryTimestamp :: At ( ts) => ts,
106+ } ;
107+ self . read_only_udf_at_ts ( request_id, path, args, identity, ts, journal, caller)
108+ . await
97109 }
98110
99111 async fn execute_public_mutation (
0 commit comments