convex-rust 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +137 -2
- package/dist/cli/bin.d.ts +2 -0
- package/dist/cli/bin.js +200 -0
- package/dist/cli/build.d.ts +146 -0
- package/dist/cli/build.js +902 -0
- package/dist/cli/demangle.d.ts +7 -0
- package/dist/cli/demangle.js +328 -0
- package/dist/cli/diagnostics.d.ts +34 -0
- package/dist/cli/diagnostics.js +296 -0
- package/dist/cli/generate.d.ts +29 -0
- package/dist/cli/generate.js +82 -0
- package/dist/cli/manifest.d.ts +24 -0
- package/dist/cli/manifest.js +75 -0
- package/dist/cli/rustApi.d.ts +78 -0
- package/dist/cli/rustApi.js +609 -0
- package/dist/cli/scaffold.d.ts +22 -0
- package/dist/cli/scaffold.js +114 -0
- package/dist/cli/shim.d.ts +30 -0
- package/dist/cli/shim.js +140 -0
- package/dist/cli/size.d.ts +17 -0
- package/dist/cli/size.js +73 -0
- package/dist/cli/split.d.ts +20 -0
- package/dist/cli/split.js +140 -0
- package/dist/cli/symbols.d.ts +30 -0
- package/dist/cli/symbols.js +133 -0
- package/dist/cli/toolchain.d.ts +53 -0
- package/dist/cli/toolchain.js +167 -0
- package/dist/cli/validators.d.ts +6 -0
- package/dist/cli/validators.js +66 -0
- package/dist/cli/wasisdk.d.ts +82 -0
- package/dist/cli/wasisdk.js +220 -0
- package/dist/cli/wasmHints.d.ts +29 -0
- package/dist/cli/wasmHints.js +172 -0
- package/dist/runtime/base64.d.ts +4 -0
- package/dist/runtime/base64.js +77 -0
- package/dist/runtime/crypto.d.ts +7 -0
- package/dist/runtime/crypto.js +421 -0
- package/dist/runtime/fastjson.d.ts +3 -0
- package/dist/runtime/fastjson.js +170 -0
- package/dist/runtime/host.d.ts +73 -0
- package/dist/runtime/host.js +1230 -0
- package/dist/runtime/http.d.ts +40 -0
- package/dist/runtime/http.js +157 -0
- package/dist/runtime/index.d.ts +2 -0
- package/dist/runtime/index.js +1 -0
- package/dist/runtime/intl.d.ts +5 -0
- package/dist/runtime/intl.js +69 -0
- package/dist/runtime/tmpfs.d.ts +129 -0
- package/dist/runtime/tmpfs.js +624 -0
- package/dist/runtime/wasi.d.ts +33 -0
- package/dist/runtime/wasi.js +216 -0
- package/package.json +57 -4
- package/rust/convex_fn/Cargo.toml +32 -0
- package/rust/convex_fn/LICENSE +201 -0
- package/rust/convex_fn/build.rs +3 -0
- package/rust/convex_fn/src/args.rs +416 -0
- package/rust/convex_fn/src/crypto.rs +237 -0
- package/rust/convex_fn/src/ctx.rs +1044 -0
- package/rust/convex_fn/src/dns.rs +356 -0
- package/rust/convex_fn/src/error.rs +179 -0
- package/rust/convex_fn/src/executor.rs +577 -0
- package/rust/convex_fn/src/fanout.rs +106 -0
- package/rust/convex_fn/src/fs.rs +19 -0
- package/rust/convex_fn/src/function_ref.rs +219 -0
- package/rust/convex_fn/src/http.rs +441 -0
- package/rust/convex_fn/src/intl.rs +75 -0
- package/rust/convex_fn/src/lib.rs +242 -0
- package/rust/convex_fn/src/logging.rs +222 -0
- package/rust/convex_fn/src/native.rs +360 -0
- package/rust/convex_fn/src/net.rs +122 -0
- package/rust/convex_fn/src/sys.rs +178 -0
- package/rust/convex_fn/src/values.rs +121 -0
- package/rust/convex_fn/src/wire.rs +579 -0
- package/rust/convex_fn_macros/Cargo.toml +13 -0
- package/rust/convex_fn_macros/LICENSE +201 -0
- package/rust/convex_fn_macros/src/derive.rs +632 -0
- package/rust/convex_fn_macros/src/lib.rs +338 -0
- package/rust/convex_reqwest/Cargo.toml +69 -0
- package/rust/convex_reqwest/LICENSE +201 -0
- package/rust/convex_reqwest/src/blocking.rs +287 -0
- package/rust/convex_reqwest/src/body.rs +152 -0
- package/rust/convex_reqwest/src/client.rs +359 -0
- package/rust/convex_reqwest/src/config_types.rs +150 -0
- package/rust/convex_reqwest/src/error.rs +241 -0
- package/rust/convex_reqwest/src/into_url.rs +57 -0
- package/rust/convex_reqwest/src/lib.rs +42 -0
- package/rust/convex_reqwest/src/multipart.rs +140 -0
- package/rust/convex_reqwest/src/request.rs +358 -0
- package/rust/convex_reqwest/src/response.rs +310 -0
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
//! Proc macros for `convex_fn`. See `contracts/ABI.md` and `contracts/MANIFEST.md`.
|
|
2
|
+
|
|
3
|
+
mod derive;
|
|
4
|
+
|
|
5
|
+
use proc_macro::TokenStream;
|
|
6
|
+
use quote::{format_ident, quote};
|
|
7
|
+
use syn::{
|
|
8
|
+
parse_macro_input, DeriveInput, FnArg, GenericArgument, ItemFn, Meta, PathArguments,
|
|
9
|
+
ReturnType, Token, Type,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/// Marks an `async fn(&Ctx, Args) -> convex_fn::Result<R>` as a Convex action.
|
|
13
|
+
///
|
|
14
|
+
/// `#[action]` makes it public (`action`), `#[action(internal)]` makes it an
|
|
15
|
+
/// `internalAction`. `Args` must implement `serde::DeserializeOwned` and `R`
|
|
16
|
+
/// `serde::Serialize`.
|
|
17
|
+
///
|
|
18
|
+
/// On every target this emits the `convex_run:<module_path>:<name>` export. The
|
|
19
|
+
/// manifest entry goes into a `convex:manifest` custom section on `wasm32` and
|
|
20
|
+
/// into an exported `convex_mf:<module_path>:<name>` static elsewhere. The
|
|
21
|
+
/// function itself is left as-is so `cargo test` can call it directly through
|
|
22
|
+
/// `convex_fn_test`.
|
|
23
|
+
#[proc_macro_attribute]
|
|
24
|
+
pub fn action(attr: TokenStream, item: TokenStream) -> TokenStream {
|
|
25
|
+
let metas = parse_macro_input!(
|
|
26
|
+
attr with syn::punctuated::Punctuated::<Meta, Token![,]>::parse_terminated
|
|
27
|
+
);
|
|
28
|
+
let mut visibility = "public";
|
|
29
|
+
for meta in &metas {
|
|
30
|
+
match meta {
|
|
31
|
+
Meta::Path(p) if p.is_ident("internal") => visibility = "internal",
|
|
32
|
+
other => {
|
|
33
|
+
return syn::Error::new_spanned(other, "expected `internal` or nothing")
|
|
34
|
+
.to_compile_error()
|
|
35
|
+
.into()
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
let func = parse_macro_input!(item as ItemFn);
|
|
41
|
+
if let Err(e) = check_signature(&func) {
|
|
42
|
+
return e.to_compile_error().into();
|
|
43
|
+
}
|
|
44
|
+
expand_action(&func, visibility, false).into()
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/// Marks an `async fn(&Ctx, HttpRequest) -> convex_fn::Result<HttpResponse>` as a Convex HTTP action.
|
|
48
|
+
///
|
|
49
|
+
/// It becomes an `httpAction` that is routed in `convex/http.ts` (`http.route({ path, method, handler:
|
|
50
|
+
/// rust.<module>.<name> })`). The request body is read as a stream (`HttpRequest::chunk`) or whole
|
|
51
|
+
/// (`bytes`, `text`, `json`); the response is buffered or streamed (`HttpResponse::streaming`). The
|
|
52
|
+
/// manifest entry has `"kind":"http"` and no validators. V8 host (cloud) only for now.
|
|
53
|
+
#[proc_macro_attribute]
|
|
54
|
+
pub fn http_action(attr: TokenStream, item: TokenStream) -> TokenStream {
|
|
55
|
+
if !attr.is_empty() {
|
|
56
|
+
return syn::Error::new(proc_macro2::Span::call_site(), "`#[http_action]` takes no arguments")
|
|
57
|
+
.to_compile_error()
|
|
58
|
+
.into();
|
|
59
|
+
}
|
|
60
|
+
let func = parse_macro_input!(item as ItemFn);
|
|
61
|
+
if let Err(e) = check_signature(&func) {
|
|
62
|
+
return e.to_compile_error().into();
|
|
63
|
+
}
|
|
64
|
+
expand_action(&func, "public", true).into()
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/// The expansion of `#[action]` for a validated function.
|
|
68
|
+
fn expand_action(func: &ItemFn, visibility: &str, http: bool) -> proc_macro2::TokenStream {
|
|
69
|
+
let name = &func.sig.ident;
|
|
70
|
+
let name_str = name.to_string();
|
|
71
|
+
let export_fn = format_ident!("__convex_run_{}", name);
|
|
72
|
+
let kind = if http { "http" } else { "" };
|
|
73
|
+
let (args_ty, returns_ty): (Type, Type) = if http {
|
|
74
|
+
(syn::parse_quote!(::convex_fn::__rt::NoReturnType), syn::parse_quote!(::convex_fn::__rt::NoReturnType))
|
|
75
|
+
} else {
|
|
76
|
+
(args_type(func), returns_type(func))
|
|
77
|
+
};
|
|
78
|
+
let run = if http {
|
|
79
|
+
quote! { ::convex_fn::__rt::run_http_export(args_ptr, args_len, |ctx, req| async move { #name(&ctx, req).await }) }
|
|
80
|
+
} else {
|
|
81
|
+
quote! { ::convex_fn::__rt::run_export(args_ptr, args_len, |ctx, args| async move { #name(&ctx, args).await }) }
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
// Split builds (`convex-rust build`, zero-config per-module wasm): the CLI compiles the crate once per
|
|
85
|
+
// Convex module with `--cfg convex_split --cfg 'convex_keep="<fn>"'` for that module's functions. A
|
|
86
|
+
// function without the cfg loses its exports (the linker's GC roots), so wasm-ld drops its code and
|
|
87
|
+
// everything only it uses. Without `convex_split` (cargo test, plain builds) nothing is gated.
|
|
88
|
+
quote! {
|
|
89
|
+
#[allow(dead_code)]
|
|
90
|
+
#func
|
|
91
|
+
|
|
92
|
+
#[allow(unexpected_cfgs)]
|
|
93
|
+
const _: () = {
|
|
94
|
+
#[cfg(any(not(convex_split), convex_keep = #name_str))]
|
|
95
|
+
#[doc(hidden)]
|
|
96
|
+
#[export_name = concat!("convex_run:", module_path!(), ":", #name_str)]
|
|
97
|
+
pub extern "C" fn #export_fn(args_ptr: *mut u8, args_len: usize) -> i64 {
|
|
98
|
+
#run
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// `Probe::<T>::VALIDATOR` is `Some(..)` when `T` implements
|
|
102
|
+
// `ConvexType` (derive `ConvexArgs`/`ConvexValue`), else `None`.
|
|
103
|
+
use ::convex_fn::__rt::NoValidator as _;
|
|
104
|
+
const __ARGS: ::core::option::Option<&'static ::convex_fn::Validator> =
|
|
105
|
+
::convex_fn::__rt::Probe::<#args_ty>::VALIDATOR;
|
|
106
|
+
const __RETURNS: ::core::option::Option<&'static ::convex_fn::Validator> =
|
|
107
|
+
::convex_fn::__rt::Probe::<#returns_ty>::VALIDATOR;
|
|
108
|
+
const __LEN: usize = ::convex_fn::__rt::manifest_len(
|
|
109
|
+
module_path!(), #name_str, #visibility, #kind, __ARGS, __RETURNS,
|
|
110
|
+
);
|
|
111
|
+
#[cfg(all(target_arch = "wasm32", any(not(convex_split), convex_keep = #name_str)))]
|
|
112
|
+
#[used]
|
|
113
|
+
#[link_section = "convex:manifest"]
|
|
114
|
+
static __CONVEX_MANIFEST: [u8; __LEN] = ::convex_fn::__rt::manifest_bytes::<__LEN>(
|
|
115
|
+
module_path!(), #name_str, #visibility, #kind, __ARGS, __RETURNS,
|
|
116
|
+
);
|
|
117
|
+
// Native: an exported symbol, found by name in the dynamic symbol table.
|
|
118
|
+
#[cfg(all(not(target_arch = "wasm32"), any(not(convex_split), convex_keep = #name_str)))]
|
|
119
|
+
#[used]
|
|
120
|
+
#[doc(hidden)]
|
|
121
|
+
#[export_name = concat!("convex_mf:", module_path!(), ":", #name_str)]
|
|
122
|
+
pub static __CONVEX_MANIFEST: [u8; __LEN] = ::convex_fn::__rt::manifest_bytes::<__LEN>(
|
|
123
|
+
module_path!(), #name_str, #visibility, #kind, __ARGS, __RETURNS,
|
|
124
|
+
);
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/// The type of the second parameter.
|
|
130
|
+
fn args_type(func: &ItemFn) -> Type {
|
|
131
|
+
match func.sig.inputs.iter().nth(1) {
|
|
132
|
+
Some(FnArg::Typed(pt)) => (*pt.ty).clone(),
|
|
133
|
+
_ => syn::parse_quote!(()),
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/// `R` of `Result<R>` / `convex_fn::Result<R>` / `Result<R, E>`; `()` otherwise
|
|
138
|
+
/// (no validator).
|
|
139
|
+
fn returns_type(func: &ItemFn) -> Type {
|
|
140
|
+
if let ReturnType::Type(_, ty) = &func.sig.output {
|
|
141
|
+
if let Type::Path(p) = &**ty {
|
|
142
|
+
if let Some(seg) = p.path.segments.last() {
|
|
143
|
+
if seg.ident == "Result" {
|
|
144
|
+
if let PathArguments::AngleBracketed(a) = &seg.arguments {
|
|
145
|
+
if let Some(GenericArgument::Type(t)) = a.args.first() {
|
|
146
|
+
return t.clone();
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
syn::parse_quote!(::convex_fn::__rt::NoReturnType)
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/// Derives `convex_fn::ConvexType` for action arguments: a static Convex
|
|
157
|
+
/// `v.object({...})` validator that matches what serde (de)serialises.
|
|
158
|
+
/// `#[action]` embeds it in the `convex:manifest`, so the backend validates
|
|
159
|
+
/// arguments like it does for TypeScript functions and the dashboard shows the
|
|
160
|
+
/// argument form.
|
|
161
|
+
///
|
|
162
|
+
/// ```ignore
|
|
163
|
+
/// #[derive(Deserialize, ConvexArgs)]
|
|
164
|
+
/// struct Args {
|
|
165
|
+
/// body: String,
|
|
166
|
+
/// #[convex(id = "users")] author: String,
|
|
167
|
+
/// limit: Option<f64>,
|
|
168
|
+
/// }
|
|
169
|
+
/// ```
|
|
170
|
+
///
|
|
171
|
+
/// Field types: `String`, `bool`, floats and integers (`v.float64()`),
|
|
172
|
+
/// `convex_fn::Int64` (`v.int64()`), `convex_fn::Bytes` (`v.bytes()`),
|
|
173
|
+
/// `Vec<T>`, `Option<T>` (optional field), `HashMap<String, T>`,
|
|
174
|
+
/// `serde_json::Value` (`v.any()`) and other `ConvexArgs`/`ConvexValue` types.
|
|
175
|
+
/// `#[convex(id = "table")]` marks a `String` as `v.id("table")`,
|
|
176
|
+
/// `#[convex(any)]` as `v.any()`. It follows the serde attributes `rename`,
|
|
177
|
+
/// `rename_all`, `default` and `skip*`.
|
|
178
|
+
#[proc_macro_derive(ConvexArgs, attributes(convex, serde))]
|
|
179
|
+
pub fn derive_convex_args(item: TokenStream) -> TokenStream {
|
|
180
|
+
let input = parse_macro_input!(item as DeriveInput);
|
|
181
|
+
derive::expand(input, derive::Mode::Args)
|
|
182
|
+
.unwrap_or_else(|e| e.to_compile_error())
|
|
183
|
+
.into()
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/// Like [`ConvexArgs`](derive@ConvexArgs) for any serde-shaped value: structs
|
|
187
|
+
/// and enums (externally, internally or adjacently tagged, or untagged).
|
|
188
|
+
/// Use it for return types and nested values.
|
|
189
|
+
#[proc_macro_derive(ConvexValue, attributes(convex, serde))]
|
|
190
|
+
pub fn derive_convex_value(item: TokenStream) -> TokenStream {
|
|
191
|
+
let input = parse_macro_input!(item as DeriveInput);
|
|
192
|
+
derive::expand(input, derive::Mode::Value)
|
|
193
|
+
.unwrap_or_else(|e| e.to_compile_error())
|
|
194
|
+
.into()
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
fn check_signature(func: &ItemFn) -> syn::Result<()> {
|
|
198
|
+
if func.sig.asyncness.is_none() {
|
|
199
|
+
return Err(syn::Error::new_spanned(
|
|
200
|
+
func.sig.fn_token,
|
|
201
|
+
"actions must be `async fn`",
|
|
202
|
+
));
|
|
203
|
+
}
|
|
204
|
+
let inputs: Vec<&FnArg> = func.sig.inputs.iter().collect();
|
|
205
|
+
if inputs.len() != 2 {
|
|
206
|
+
return Err(syn::Error::new_spanned(
|
|
207
|
+
&func.sig,
|
|
208
|
+
"a Convex action takes exactly two parameters: `(ctx: &Ctx, args: Args)`",
|
|
209
|
+
));
|
|
210
|
+
}
|
|
211
|
+
match inputs[0] {
|
|
212
|
+
FnArg::Receiver(r) => {
|
|
213
|
+
return Err(syn::Error::new_spanned(r, "actions cannot take `self`"));
|
|
214
|
+
}
|
|
215
|
+
FnArg::Typed(pt) => match &*pt.ty {
|
|
216
|
+
Type::Reference(r) if r.mutability.is_none() => {}
|
|
217
|
+
other => {
|
|
218
|
+
return Err(syn::Error::new_spanned(
|
|
219
|
+
other,
|
|
220
|
+
"the first parameter must be `ctx: &Ctx` (a shared reference)",
|
|
221
|
+
))
|
|
222
|
+
}
|
|
223
|
+
},
|
|
224
|
+
}
|
|
225
|
+
if let FnArg::Receiver(r) = inputs[1] {
|
|
226
|
+
return Err(syn::Error::new_spanned(r, "actions cannot take `self`"));
|
|
227
|
+
}
|
|
228
|
+
if matches!(func.sig.output, ReturnType::Default) {
|
|
229
|
+
return Err(syn::Error::new_spanned(
|
|
230
|
+
&func.sig,
|
|
231
|
+
"actions must return `convex_fn::Result<R>`",
|
|
232
|
+
));
|
|
233
|
+
}
|
|
234
|
+
if !func.sig.generics.params.is_empty() {
|
|
235
|
+
return Err(syn::Error::new_spanned(
|
|
236
|
+
&func.sig.generics,
|
|
237
|
+
"actions cannot be generic",
|
|
238
|
+
));
|
|
239
|
+
}
|
|
240
|
+
Ok(())
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
#[cfg(test)]
|
|
244
|
+
mod tests {
|
|
245
|
+
use super::*;
|
|
246
|
+
|
|
247
|
+
fn check(src: &str) -> Result<(), String> {
|
|
248
|
+
let f: ItemFn = syn::parse_str(src).unwrap();
|
|
249
|
+
check_signature(&f).map_err(|e| e.to_string())
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
fn expansion(src: &str, vis: &str) -> String {
|
|
253
|
+
let f: ItemFn = syn::parse_str(src).unwrap();
|
|
254
|
+
let ts = expand_action(&f, vis, false);
|
|
255
|
+
// Normalise whitespace so the assertions do not depend on token printing.
|
|
256
|
+
ts.to_string().split_whitespace().collect::<Vec<_>>().join(" ")
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
#[test]
|
|
260
|
+
fn expansion_exports_on_all_targets() {
|
|
261
|
+
let out = expansion("async fn f(ctx: &Ctx, a: A) -> Result<R> { todo!() }", "public");
|
|
262
|
+
// The run export is not gated on the target.
|
|
263
|
+
let run = out.find("convex_run:").expect("run export");
|
|
264
|
+
assert!(!out[..run].contains("# [cfg (target_arch"), "{out}");
|
|
265
|
+
assert!(out.contains("pub extern \"C\" fn __convex_run_f"), "{out}");
|
|
266
|
+
assert!(out.contains("__rt :: run_export"), "{out}");
|
|
267
|
+
// wasm manifest: custom section; native manifest: exported symbol.
|
|
268
|
+
assert!(out.contains(
|
|
269
|
+
"# [cfg (all (target_arch = \"wasm32\" , any (not (convex_split) , convex_keep = \"f\")))] # [used] # [link_section = \"convex:manifest\"] static __CONVEX_MANIFEST"
|
|
270
|
+
), "{out}");
|
|
271
|
+
assert!(out.contains(
|
|
272
|
+
"# [cfg (all (not (target_arch = \"wasm32\") , any (not (convex_split) , convex_keep = \"f\")))] # [used] # [doc (hidden)] # [export_name = concat ! (\"convex_mf:\" , module_path ! () , \":\" , \"f\")] pub static __CONVEX_MANIFEST"
|
|
273
|
+
), "{out}");
|
|
274
|
+
assert!(!out.contains("convex_native"), "{out}");
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
#[test]
|
|
278
|
+
fn http_expansion_runs_the_http_export_and_marks_the_manifest() {
|
|
279
|
+
let f: ItemFn = syn::parse_str("async fn h(ctx: &Ctx, r: HttpRequest) -> Result<HttpResponse> { todo!() }").unwrap();
|
|
280
|
+
let out = expand_action(&f, "public", true).to_string().split_whitespace().collect::<Vec<_>>().join(" ");
|
|
281
|
+
assert!(out.contains("__rt :: run_http_export"), "{out}");
|
|
282
|
+
assert!(!out.contains("__rt :: run_export"), "{out}");
|
|
283
|
+
assert!(out.contains("\"public\" , \"http\" , __ARGS , __RETURNS"), "{out}");
|
|
284
|
+
assert!(out.contains("Probe :: < :: convex_fn :: __rt :: NoReturnType >"), "{out}");
|
|
285
|
+
// Actions carry an empty kind (omitted from the manifest).
|
|
286
|
+
let a = expansion("async fn f(ctx: &Ctx, a: A) -> Result<R> { todo!() }", "public");
|
|
287
|
+
assert!(a.contains("\"public\" , \"\" , __ARGS"), "{a}");
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
#[test]
|
|
291
|
+
fn expansion_internal_visibility() {
|
|
292
|
+
let out = expansion("async fn g(ctx: &Ctx, a: A) -> Result<R> { todo!() }", "internal");
|
|
293
|
+
assert!(out.contains("\"internal\""), "{out}");
|
|
294
|
+
assert!(out.contains("\"convex_mf:\""), "{out}");
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
#[test]
|
|
298
|
+
fn accepts_valid_signature() {
|
|
299
|
+
assert!(check("async fn f(ctx: &Ctx, a: Args) -> Result<R> { todo!() }").is_ok());
|
|
300
|
+
assert!(check("async fn f(_: &Ctx, _: ()) -> convex_fn::Result<()> { Ok(()) }").is_ok());
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
#[test]
|
|
304
|
+
fn rejects_non_async() {
|
|
305
|
+
let e = check("fn f(ctx: &Ctx, a: A) -> Result<R> { todo!() }").unwrap_err();
|
|
306
|
+
assert!(e.contains("async fn"), "{e}");
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
#[test]
|
|
310
|
+
fn rejects_wrong_arity() {
|
|
311
|
+
for src in [
|
|
312
|
+
"async fn f(ctx: &Ctx) -> Result<R> { todo!() }",
|
|
313
|
+
"async fn f(ctx: &Ctx, a: A, b: B) -> Result<R> { todo!() }",
|
|
314
|
+
"async fn f() -> Result<R> { todo!() }",
|
|
315
|
+
] {
|
|
316
|
+
let e = check(src).unwrap_err();
|
|
317
|
+
assert!(e.contains("exactly two parameters"), "{e}");
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
#[test]
|
|
322
|
+
fn rejects_bad_ctx_and_receivers() {
|
|
323
|
+
let e = check("async fn f(ctx: Ctx, a: A) -> Result<R> { todo!() }").unwrap_err();
|
|
324
|
+
assert!(e.contains("ctx: &Ctx"), "{e}");
|
|
325
|
+
let e = check("async fn f(ctx: &mut Ctx, a: A) -> Result<R> { todo!() }").unwrap_err();
|
|
326
|
+
assert!(e.contains("shared reference"), "{e}");
|
|
327
|
+
let e = check("async fn f(&self, a: A) -> Result<R> { todo!() }").unwrap_err();
|
|
328
|
+
assert!(e.contains("self"), "{e}");
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
#[test]
|
|
332
|
+
fn rejects_generics_and_missing_return() {
|
|
333
|
+
let e = check("async fn f<T>(ctx: &Ctx, a: T) -> Result<R> { todo!() }").unwrap_err();
|
|
334
|
+
assert!(e.contains("generic"), "{e}");
|
|
335
|
+
let e = check("async fn f(ctx: &Ctx, a: A) { }").unwrap_err();
|
|
336
|
+
assert!(e.contains("convex_fn::Result"), "{e}");
|
|
337
|
+
}
|
|
338
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
# Named `reqwest` so `[patch.crates-io] reqwest = { path = ... }` swaps it in.
|
|
3
|
+
# The version only has to satisfy the `0.12` requirement of vendor crates.
|
|
4
|
+
name = "reqwest"
|
|
5
|
+
version = "0.12.99"
|
|
6
|
+
edition = "2021"
|
|
7
|
+
license = "Apache-2.0"
|
|
8
|
+
description = "reqwest-compatible HTTP client for \"use rust\" actions, backed by the Convex fetch task (DX-06 / D-010)"
|
|
9
|
+
publish = false
|
|
10
|
+
|
|
11
|
+
[lib]
|
|
12
|
+
path = "src/lib.rs"
|
|
13
|
+
|
|
14
|
+
[dependencies]
|
|
15
|
+
convex_fn = { path = "../convex_fn", features = ["tokio-rt"] }
|
|
16
|
+
bytes = "1"
|
|
17
|
+
http = "1"
|
|
18
|
+
http-body = "1"
|
|
19
|
+
url = "2"
|
|
20
|
+
serde = "1"
|
|
21
|
+
serde_json = "1"
|
|
22
|
+
serde_urlencoded = "0.7"
|
|
23
|
+
futures-core = { version = "0.3", default-features = false }
|
|
24
|
+
futures-util = { version = "0.3", default-features = false }
|
|
25
|
+
base64 = "0.22"
|
|
26
|
+
tokio = { version = "1", default-features = false, features = ["rt", "time"] }
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
[features]
|
|
30
|
+
default = ["default-tls", "charset", "http2", "macos-system-configuration"]
|
|
31
|
+
default-tls = []
|
|
32
|
+
native-tls = []
|
|
33
|
+
native-tls-vendored = []
|
|
34
|
+
native-tls-alpn = []
|
|
35
|
+
rustls-tls = []
|
|
36
|
+
rustls-tls-no-provider = []
|
|
37
|
+
rustls-tls-manual-roots = []
|
|
38
|
+
rustls-tls-manual-roots-no-provider = []
|
|
39
|
+
rustls-tls-webpki-roots = []
|
|
40
|
+
rustls-tls-webpki-roots-no-provider = []
|
|
41
|
+
rustls-tls-native-roots = []
|
|
42
|
+
rustls-tls-native-roots-no-provider = []
|
|
43
|
+
blocking = []
|
|
44
|
+
json = []
|
|
45
|
+
multipart = []
|
|
46
|
+
stream = []
|
|
47
|
+
query = []
|
|
48
|
+
form = []
|
|
49
|
+
gzip = []
|
|
50
|
+
brotli = []
|
|
51
|
+
zstd = []
|
|
52
|
+
deflate = []
|
|
53
|
+
cookies = []
|
|
54
|
+
socks = []
|
|
55
|
+
hickory-dns = []
|
|
56
|
+
trust-dns = []
|
|
57
|
+
http2 = []
|
|
58
|
+
http3 = []
|
|
59
|
+
charset = []
|
|
60
|
+
macos-system-configuration = []
|
|
61
|
+
system-proxy = []
|
|
62
|
+
native-roots = []
|
|
63
|
+
webpki-roots = []
|
|
64
|
+
# reqwest 0.13 names
|
|
65
|
+
rustls = []
|
|
66
|
+
rustls-no-provider = []
|
|
67
|
+
rustls-native-roots = []
|
|
68
|
+
rustls-webpki-roots = []
|
|
69
|
+
native-tls-no-alpn = []
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Tomás Domingos
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|