Stream: wit-bindgen

Topic: WIT field renaming


view this post on Zulip Landon James (Mar 25 2024 at 04:22):

Are there any plans to allow explicit renaming of fields in WIT types, and if so would that metadata be passed through to the host language code generators? My use case is that I would like to use some very basic javascript objects/python dicts that I do not control as inputs to my WIT-specified functions. But the names of the fields in these objects/dicts don't always perfectly align with the standard language conventions (ex: javascript bindings make all WIT foo-bar into js fooBar, but the field on my object is FooBar).

The specific things I want to model are AWS Lambda events. These are always JSON inputs and so have fairly primitive types that should be modelable in WIT (besides the lack of an arbitrary dict/map type). But as you can see in this example not all of the fields conform to standard javascript camelCase convention (ex: Records, x-amz-request-id). I would hope for something similar to the #[serde(rename = "name")] attribute to force my preferred name through all of the wit codegen steps.

This isn't a huge blocker since at the moment I can just JSON.stringify the input and pass it to my wasm as a string and do the serde work inside the wasm, but the extra two hops in the js/py in memory -> js/py string -> FFI boundary -> wasm string -> wasm struct process are a bit unergonomic.

view this post on Zulip adam (Mar 25 2024 at 05:19):

A Java developer would prescribe a layer of intermediary types and mapping to those types so you're not leaking a dependency library's types in your interface

view this post on Zulip Alex Crichton (Mar 25 2024 at 15:01):

It's long been a desire to have a sort of attribute syntax in WIT for precisely this sort of use case. This is not implemented yet nor has it yet been designed, but the thinking is that we'd basically have the serde-rename attribute lookalike in one form or another yeah.


Last updated: Nov 22 2024 at 17:03 UTC