[BUG] RPC Method Proxy Issues: Export and Usability
RPC methods are being proxied, which makes usage difficult. In the index.d.ts file, export is specified, but the generated index.js exports a Proxy. This also causes a "not found" error, similar to the example. RPC methods should be moved outside the proxy.
https://github.com/cloudflare/workers-rs/blob/490c6c9082e06db5e29a6d622f37893628191396/worker-build/src/js/shim.js#L113
lib.rs:
#[wasm_bindgen]
pub async fn greet()
build/index.d.ts:
export function greet(): void;
demo.ts:
import {greet} from "./build/index.js" //throw error not found greet
If you need directly exported functions, that you want to consume from JS, that is possible using the #wasm_bindgen attribute on the function.
Formally, RPC definitions do not imply an export of the underlying library, only the cloudflare RPC entry point configuration export.
Or am I misunderstanding the use case for importing here?
I'm not using the default shim file. I'm using a custom shim. Therefore, I need to access the event and rpc methods using import. The generated build/index.d.ts file tells me that they are exported, but in the build/index.js file, the proxy is being exported. So there's an inconsistency.
Custom shims are in the process of being deprecated to rather lean into the wasm bindgen macro customizations, although this process is ongoing.
I'd be interested to hear how and why you are using a custom shim here though, to figure out how we can ensure your use case is supported without custom shims.
I'm using custom shims to use JavaScript and Rust code together. If the custom shims are deprecated, how can I use the two code structures together?
I'm using custom shims to use JavaScript and Rust code together. If the custom shims are deprecated, how can I use the two code structures together?
Can you share more about the use case? The idea is that you could use standards Wasm Bindgen patterns instead - JS Snippets, declaring exports / imports, etc.