Skip to content

Commit

Permalink
Support optional result fields (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrzejressel authored Apr 1, 2024
1 parent 3bb86bc commit fa39f3e
Show file tree
Hide file tree
Showing 23 changed files with 503 additions and 434 deletions.
7 changes: 7 additions & 0 deletions examples/simple/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@ build:
run:
just build
cargo run -p pulumi_wasm_runner -- run --wasm ../../target/wasm32-wasi/debug/composed.wasm

[windows]
local-test:
#!pwsh
$env:PULUMI_CONFIG_PASSPHRASE=" "
pulumi destroy -y
pulumi up -y
4 changes: 4 additions & 0 deletions examples/simple/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ fn test_main() -> Result<(), Error> {
special: None.into(),
upper: None.into(),
});

let t = random_string.result.map(|s| format!("Result: {s}"));

add_export("result", random_string.result);
add_export("transformed_result", t);
Ok(())
}
7 changes: 7 additions & 0 deletions examples/simple/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,14 @@ fn test_integration() -> Result<(), anyhow::Error> {
.as_str()
.ok_or(anyhow!("[result] is not a string"))?;

let transformed_result = stack
.pointer("/transformed_result")
.ok_or(anyhow!("Cannot find [transformed_result] in stack export"))?
.as_str()
.ok_or(anyhow!("[transformed_result] is not a string"))?;

assert_eq!(result.len(), 36);
assert_eq!(transformed_result, format!("Result: {}", result));

Ok(())
}
130 changes: 69 additions & 61 deletions providers/pulumi_wasm_provider_random/src/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ pub mod component {
}
impl Output {
#[allow(unused_unsafe, clippy::all)]
pub fn get_field(&self, field: &str) -> Output {
pub fn get_field(&self, field: &str, required: bool) -> Output {
unsafe {
let vec0 = field;
let ptr0 = vec0.as_ptr().cast::<u8>();
Expand All @@ -197,14 +197,22 @@ pub mod component {
#[link(wasm_import_module = "component:pulumi-wasm/[email protected]")]
extern "C" {
#[link_name = "[method]output.get-field"]
fn wit_import(_: i32, _: *mut u8, _: usize) -> i32;
fn wit_import(_: i32, _: *mut u8, _: usize, _: i32) -> i32;
}

#[cfg(not(target_arch = "wasm32"))]
fn wit_import(_: i32, _: *mut u8, _: usize) -> i32 {
fn wit_import(_: i32, _: *mut u8, _: usize, _: i32) -> i32 {
unreachable!()
}
let ret = wit_import((self).handle() as i32, ptr0.cast_mut(), len0);
let ret = wit_import(
(self).handle() as i32,
ptr0.cast_mut(),
len0,
match &required {
true => 1,
false => 0,
},
);
Output::from_handle(ret as u32)
}
}
Expand Down Expand Up @@ -1615,66 +1623,66 @@ pub(crate) use __export_main_world_impl as export;
#[cfg(target_arch = "wasm32")]
#[link_section = "component-type:wit-bindgen:0.21.0:main-world:encoded world"]
#[doc(hidden)]
pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 2581] = *b"\
\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\x94\x13\x01A\x02\x01\
pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 2591] = *b"\
\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\x9e\x13\x01A\x02\x01\
A\x15\x01B\x15\x04\0\x06output\x03\x01\x01p}\x01i\0\x01@\x01\x05value\x01\0\x02\x04\
\0\x13[constructor]output\x01\x03\x01h\0\x01@\x02\x04self\x04\x0dfunction-names\0\
\x02\x04\0\x12[method]output.map\x01\x05\x01k\x01\x01@\x01\x04self\x04\0\x06\x04\
\0\x12[method]output.get\x01\x07\x01@\x02\x04self\x04\x05fields\0\x02\x04\0\x18[\
method]output.get-field\x01\x08\x01@\x01\x04self\x04\0s\x04\0\x17[method]output.\
get-type\x01\x09\x01@\x01\x04self\x04\0\x02\x04\0\x18[method]output.duplicate\x01\
\x0a\x01@\0\0s\x04\0\x10describe-outputs\x01\x0b\x01@\0\0\x7f\x04\0\x0fnon-done-\
exists\x01\x0c\x03\x01,component:pulumi-wasm/[email protected].0\x05\0\x02\x03\
\0\0\x06output\x01B\x0b\x02\x03\x02\x01\x01\x04\0\x06output\x03\0\0\x01h\x01\x01\
r\x02\x04names\x05value\x02\x04\0\x0cobject-field\x03\0\x03\x01p\x04\x01r\x03\x04\
types\x04names\x06object\x05\x04\0\x19register-resource-request\x03\0\x06\x01i\x01\
\x01@\x01\x07request\x07\0\x08\x04\0\x08register\x01\x09\x03\x01.component:pulum\
i-wasm/[email protected]\x05\x02\x01B\x0a\x02\x03\x02\x01\x01\x04\0\x06ou\
tput\x03\0\0\x01h\x01\x01r\x02\x07keepers\x02\x06length\x02\x04\0\x04args\x03\0\x03\
\x01i\x01\x01r\x04\x06base64\x05\x03hex\x05\x07keepers\x05\x06length\x05\x04\0\x03\
res\x03\0\x06\x01@\x02\x04names\x04args\x04\0\x07\x04\0\x06invoke\x01\x08\x04\x01\
!pulumi:random/[email protected]\x05\x03\x01B\x0a\x02\x03\x02\x01\x01\x04\0\x06\
output\x03\0\0\x01h\x01\x01r\x03\x0bbyte-length\x02\x07keepers\x02\x06prefix\x02\
\x04\0\x04args\x03\0\x03\x01i\x01\x01r\x07\x07b64-std\x05\x07b64-url\x05\x0bbyte\
-length\x05\x03dec\x05\x03hex\x05\x07keepers\x05\x06prefix\x05\x04\0\x03res\x03\0\
\x06\x01@\x02\x04names\x04args\x04\0\x07\x04\0\x06invoke\x01\x08\x04\x01\x1epulu\
mi:random/[email protected]\x05\x04\x01B\x0a\x02\x03\x02\x01\x01\x04\0\x06output\x03\
\0\0\x01h\x01\x01r\x04\x07keepers\x02\x03max\x02\x03min\x02\x04seed\x02\x04\0\x04\
args\x03\0\x03\x01i\x01\x01r\x05\x07keepers\x05\x03max\x05\x03min\x05\x06result\x05\
\x04seed\x05\x04\0\x03res\x03\0\x06\x01@\x02\x04names\x04args\x04\0\x07\x04\0\x06\
invoke\x01\x08\x04\x01#pulumi:random/[email protected]\x05\x05\x01B\x0a\x02\x03\
\x02\x01\x01\x04\0\x06output\x03\0\0\x01h\x01\x01r\x0c\x07keepers\x02\x06length\x02\
\x05lower\x02\x09min-lower\x02\x0bmin-numeric\x02\x0bmin-special\x02\x09min-uppe\
r\x02\x06number\x02\x07numeric\x02\x10override-special\x02\x07special\x02\x05upp\
er\x02\x04\0\x04args\x03\0\x03\x01i\x01\x01r\x0e\x0bbcrypt-hash\x05\x07keepers\x05\
\x06length\x05\x05lower\x05\x09min-lower\x05\x0bmin-numeric\x05\x0bmin-special\x05\
\x09min-upper\x05\x06number\x05\x07numeric\x05\x10override-special\x05\x06result\
\x05\x07special\x05\x05upper\x05\x04\0\x03res\x03\0\x06\x01@\x02\x04names\x04arg\
s\x04\0\x07\x04\0\x06invoke\x01\x08\x04\x01$pulumi:random/[email protected]\
\x05\x06\x01B\x0a\x02\x03\x02\x01\x01\x04\0\x06output\x03\0\0\x01h\x01\x01r\x04\x07\
keepers\x02\x06length\x02\x06prefix\x02\x09separator\x02\x04\0\x04args\x03\0\x03\
\x01i\x01\x01r\x04\x07keepers\x05\x06length\x05\x06prefix\x05\x09separator\x05\x04\
\0\x03res\x03\0\x06\x01@\x02\x04names\x04args\x04\0\x07\x04\0\x06invoke\x01\x08\x04\
\x01\x1fpulumi:random/[email protected]\x05\x07\x01B\x0a\x02\x03\x02\x01\x01\x04\
\0\x06output\x03\0\0\x01h\x01\x01r\x04\x06inputs\x02\x07keepers\x02\x0cresult-co\
unt\x02\x04seed\x02\x04\0\x04args\x03\0\x03\x01i\x01\x01r\x05\x06inputs\x05\x07k\
eepers\x05\x0cresult-count\x05\x07results\x05\x04seed\x05\x04\0\x03res\x03\0\x06\
\x01@\x02\x04names\x04args\x04\0\x07\x04\0\x06invoke\x01\x08\x04\x01#pulumi:rand\
om/[email protected]\x05\x08\x01B\x0a\x02\x03\x02\x01\x01\x04\0\x06output\x03\
\0\0\x01h\x01\x01r\x0c\x07keepers\x02\x06length\x02\x05lower\x02\x09min-lower\x02\
\x0bmin-numeric\x02\x0bmin-special\x02\x09min-upper\x02\x06number\x02\x07numeric\
\x02\x10override-special\x02\x07special\x02\x05upper\x02\x04\0\x04args\x03\0\x03\
\x01i\x01\x01r\x0d\x07keepers\x05\x06length\x05\x05lower\x05\x09min-lower\x05\x0b\
min-numeric\x05\x0bmin-special\x05\x09min-upper\x05\x06number\x05\x07numeric\x05\
\x10override-special\x05\x06result\x05\x07special\x05\x05upper\x05\x04\0\x03res\x03\
\0\x06\x01@\x02\x04names\x04args\x04\0\x07\x04\0\x06invoke\x01\x08\x04\x01\"pulu\
mi:random/[email protected]\x05\x09\x01B\x0a\x02\x03\x02\x01\x01\x04\0\x06out\
put\x03\0\0\x01h\x01\x01r\x01\x07keepers\x02\x04\0\x04args\x03\0\x03\x01i\x01\x01\
r\x02\x07keepers\x05\x06result\x05\x04\0\x03res\x03\0\x06\x01@\x02\x04names\x04a\
rgs\x04\0\x07\x04\0\x06invoke\x01\x08\x04\x01\x20pulumi:random/[email protected].\
0\x05\x0a\x04\x01\x1fpulumi:random/[email protected]\x04\0\x0b\x10\x01\0\x0amain\
-world\x03\0\0\0G\x09producers\x01\x0cprocessed-by\x02\x0dwit-component\x070.201\
.0\x10wit-bindgen-rust\x060.21.0";
\0\x12[method]output.get\x01\x07\x01@\x03\x04self\x04\x05fields\x08required\x7f\0\
\x02\x04\0\x18[method]output.get-field\x01\x08\x01@\x01\x04self\x04\0s\x04\0\x17\
[method]output.get-type\x01\x09\x01@\x01\x04self\x04\0\x02\x04\0\x18[method]outp\
ut.duplicate\x01\x0a\x01@\0\0s\x04\0\x10describe-outputs\x01\x0b\x01@\0\0\x7f\x04\
\0\x0fnon-done-exists\x01\x0c\x03\x01,component:pulumi-wasm/[email protected]\
.0\x05\0\x02\x03\0\0\x06output\x01B\x0b\x02\x03\x02\x01\x01\x04\0\x06output\x03\0\
\0\x01h\x01\x01r\x02\x04names\x05value\x02\x04\0\x0cobject-field\x03\0\x03\x01p\x04\
\x01r\x03\x04types\x04names\x06object\x05\x04\0\x19register-resource-request\x03\
\0\x06\x01i\x01\x01@\x01\x07request\x07\0\x08\x04\0\x08register\x01\x09\x03\x01.\
component:pulumi-wasm/[email protected]\x05\x02\x01B\x0a\x02\x03\x02\x01\x01\
\x04\0\x06output\x03\0\0\x01h\x01\x01r\x02\x07keepers\x02\x06length\x02\x04\0\x04\
args\x03\0\x03\x01i\x01\x01r\x04\x06base64\x05\x03hex\x05\x07keepers\x05\x06leng\
th\x05\x04\0\x03res\x03\0\x06\x01@\x02\x04names\x04args\x04\0\x07\x04\0\x06invok\
e\x01\x08\x04\x01!pulumi:random/[email protected]\x05\x03\x01B\x0a\x02\x03\x02\
\x01\x01\x04\0\x06output\x03\0\0\x01h\x01\x01r\x03\x0bbyte-length\x02\x07keepers\
\x02\x06prefix\x02\x04\0\x04args\x03\0\x03\x01i\x01\x01r\x07\x07b64-std\x05\x07b\
64-url\x05\x0bbyte-length\x05\x03dec\x05\x03hex\x05\x07keepers\x05\x06prefix\x05\
\x04\0\x03res\x03\0\x06\x01@\x02\x04names\x04args\x04\0\x07\x04\0\x06invoke\x01\x08\
\x04\x01\x1epulumi:random/[email protected]\x05\x04\x01B\x0a\x02\x03\x02\x01\x01\x04\
\0\x06output\x03\0\0\x01h\x01\x01r\x04\x07keepers\x02\x03max\x02\x03min\x02\x04s\
eed\x02\x04\0\x04args\x03\0\x03\x01i\x01\x01r\x05\x07keepers\x05\x03max\x05\x03m\
in\x05\x06result\x05\x04seed\x05\x04\0\x03res\x03\0\x06\x01@\x02\x04names\x04arg\
s\x04\0\x07\x04\0\x06invoke\x01\x08\x04\x01#pulumi:random/[email protected]\x05\
\x05\x01B\x0a\x02\x03\x02\x01\x01\x04\0\x06output\x03\0\0\x01h\x01\x01r\x0c\x07k\
eepers\x02\x06length\x02\x05lower\x02\x09min-lower\x02\x0bmin-numeric\x02\x0bmin\
-special\x02\x09min-upper\x02\x06number\x02\x07numeric\x02\x10override-special\x02\
\x07special\x02\x05upper\x02\x04\0\x04args\x03\0\x03\x01i\x01\x01r\x0e\x0bbcrypt\
-hash\x05\x07keepers\x05\x06length\x05\x05lower\x05\x09min-lower\x05\x0bmin-nume\
ric\x05\x0bmin-special\x05\x09min-upper\x05\x06number\x05\x07numeric\x05\x10over\
ride-special\x05\x06result\x05\x07special\x05\x05upper\x05\x04\0\x03res\x03\0\x06\
\x01@\x02\x04names\x04args\x04\0\x07\x04\0\x06invoke\x01\x08\x04\x01$pulumi:rand\
om/[email protected]\x05\x06\x01B\x0a\x02\x03\x02\x01\x01\x04\0\x06output\x03\
\0\0\x01h\x01\x01r\x04\x07keepers\x02\x06length\x02\x06prefix\x02\x09separator\x02\
\x04\0\x04args\x03\0\x03\x01i\x01\x01r\x04\x07keepers\x05\x06length\x05\x06prefi\
x\x05\x09separator\x05\x04\0\x03res\x03\0\x06\x01@\x02\x04names\x04args\x04\0\x07\
\x04\0\x06invoke\x01\x08\x04\x01\x1fpulumi:random/[email protected]\x05\x07\x01B\
\x0a\x02\x03\x02\x01\x01\x04\0\x06output\x03\0\0\x01h\x01\x01r\x04\x06inputs\x02\
\x07keepers\x02\x0cresult-count\x02\x04seed\x02\x04\0\x04args\x03\0\x03\x01i\x01\
\x01r\x05\x06inputs\x05\x07keepers\x05\x0cresult-count\x05\x07results\x05\x04see\
d\x05\x04\0\x03res\x03\0\x06\x01@\x02\x04names\x04args\x04\0\x07\x04\0\x06invoke\
\x01\x08\x04\x01#pulumi:random/[email protected]\x05\x08\x01B\x0a\x02\x03\x02\
\x01\x01\x04\0\x06output\x03\0\0\x01h\x01\x01r\x0c\x07keepers\x02\x06length\x02\x05\
lower\x02\x09min-lower\x02\x0bmin-numeric\x02\x0bmin-special\x02\x09min-upper\x02\
\x06number\x02\x07numeric\x02\x10override-special\x02\x07special\x02\x05upper\x02\
\x04\0\x04args\x03\0\x03\x01i\x01\x01r\x0d\x07keepers\x05\x06length\x05\x05lower\
\x05\x09min-lower\x05\x0bmin-numeric\x05\x0bmin-special\x05\x09min-upper\x05\x06\
number\x05\x07numeric\x05\x10override-special\x05\x06result\x05\x07special\x05\x05\
upper\x05\x04\0\x03res\x03\0\x06\x01@\x02\x04names\x04args\x04\0\x07\x04\0\x06in\
voke\x01\x08\x04\x01\"pulumi:random/[email protected]\x05\x09\x01B\x0a\x02\x03\
\x02\x01\x01\x04\0\x06output\x03\0\0\x01h\x01\x01r\x01\x07keepers\x02\x04\0\x04a\
rgs\x03\0\x03\x01i\x01\x01r\x02\x07keepers\x05\x06result\x05\x04\0\x03res\x03\0\x06\
\x01@\x02\x04names\x04args\x04\0\x07\x04\0\x06invoke\x01\x08\x04\x01\x20pulumi:r\
andom/[email protected].0\x05\x0a\x04\x01\x1fpulumi:random/[email protected]\x04\0\
\x0b\x10\x01\0\x0amain-world\x03\0\0\0G\x09producers\x01\x0cprocessed-by\x02\x0d\
wit-component\x070.201.0\x10wit-bindgen-rust\x060.21.0";

#[inline(never)]
#[doc(hidden)]
Expand Down
108 changes: 54 additions & 54 deletions providers/pulumi_wasm_provider_random/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ impl random_bytes::Guest for Component {
let o = register(&request);

random_bytes::Res {
base64: o.get_field("base64"),
hex: o.get_field("hex"),
keepers: o.get_field("keepers"),
length: o.get_field("length"),
base64: o.get_field("base64", true),
hex: o.get_field("hex", true),
keepers: o.get_field("keepers", false),
length: o.get_field("length", true),
}
}
}
Expand Down Expand Up @@ -72,13 +72,13 @@ impl random_id::Guest for Component {
let o = register(&request);

random_id::Res {
b64_std: o.get_field("b64Std"),
b64_url: o.get_field("b64Url"),
byte_length: o.get_field("byteLength"),
dec: o.get_field("dec"),
hex: o.get_field("hex"),
keepers: o.get_field("keepers"),
prefix: o.get_field("prefix"),
b64_std: o.get_field("b64Std", true),
b64_url: o.get_field("b64Url", true),
byte_length: o.get_field("byteLength", true),
dec: o.get_field("dec", true),
hex: o.get_field("hex", true),
keepers: o.get_field("keepers", false),
prefix: o.get_field("prefix", false),
}
}
}
Expand Down Expand Up @@ -111,11 +111,11 @@ impl random_integer::Guest for Component {
let o = register(&request);

random_integer::Res {
keepers: o.get_field("keepers"),
max: o.get_field("max"),
min: o.get_field("min"),
result: o.get_field("result"),
seed: o.get_field("seed"),
keepers: o.get_field("keepers", false),
max: o.get_field("max", true),
min: o.get_field("min", true),
result: o.get_field("result", true),
seed: o.get_field("seed", false),
}
}
}
Expand Down Expand Up @@ -180,20 +180,20 @@ impl random_password::Guest for Component {
let o = register(&request);

random_password::Res {
bcrypt_hash: o.get_field("bcryptHash"),
keepers: o.get_field("keepers"),
length: o.get_field("length"),
lower: o.get_field("lower"),
min_lower: o.get_field("minLower"),
min_numeric: o.get_field("minNumeric"),
min_special: o.get_field("minSpecial"),
min_upper: o.get_field("minUpper"),
number: o.get_field("number"),
numeric: o.get_field("numeric"),
override_special: o.get_field("overrideSpecial"),
result: o.get_field("result"),
special: o.get_field("special"),
upper: o.get_field("upper"),
bcrypt_hash: o.get_field("bcryptHash", true),
keepers: o.get_field("keepers", false),
length: o.get_field("length", true),
lower: o.get_field("lower", true),
min_lower: o.get_field("minLower", true),
min_numeric: o.get_field("minNumeric", true),
min_special: o.get_field("minSpecial", true),
min_upper: o.get_field("minUpper", true),
number: o.get_field("number", true),
numeric: o.get_field("numeric", true),
override_special: o.get_field("overrideSpecial", false),
result: o.get_field("result", true),
special: o.get_field("special", true),
upper: o.get_field("upper", true),
}
}
}
Expand Down Expand Up @@ -226,10 +226,10 @@ impl random_pet::Guest for Component {
let o = register(&request);

random_pet::Res {
keepers: o.get_field("keepers"),
length: o.get_field("length"),
prefix: o.get_field("prefix"),
separator: o.get_field("separator"),
keepers: o.get_field("keepers", false),
length: o.get_field("length", true),
prefix: o.get_field("prefix", false),
separator: o.get_field("separator", true),
}
}
}
Expand Down Expand Up @@ -262,11 +262,11 @@ impl random_shuffle::Guest for Component {
let o = register(&request);

random_shuffle::Res {
inputs: o.get_field("inputs"),
keepers: o.get_field("keepers"),
result_count: o.get_field("resultCount"),
results: o.get_field("results"),
seed: o.get_field("seed"),
inputs: o.get_field("inputs", true),
keepers: o.get_field("keepers", false),
result_count: o.get_field("resultCount", false),
results: o.get_field("results", true),
seed: o.get_field("seed", false),
}
}
}
Expand Down Expand Up @@ -331,19 +331,19 @@ impl random_string::Guest for Component {
let o = register(&request);

random_string::Res {
keepers: o.get_field("keepers"),
length: o.get_field("length"),
lower: o.get_field("lower"),
min_lower: o.get_field("minLower"),
min_numeric: o.get_field("minNumeric"),
min_special: o.get_field("minSpecial"),
min_upper: o.get_field("minUpper"),
number: o.get_field("number"),
numeric: o.get_field("numeric"),
override_special: o.get_field("overrideSpecial"),
result: o.get_field("result"),
special: o.get_field("special"),
upper: o.get_field("upper"),
keepers: o.get_field("keepers", false),
length: o.get_field("length", true),
lower: o.get_field("lower", true),
min_lower: o.get_field("minLower", true),
min_numeric: o.get_field("minNumeric", true),
min_special: o.get_field("minSpecial", true),
min_upper: o.get_field("minUpper", true),
number: o.get_field("number", true),
numeric: o.get_field("numeric", true),
override_special: o.get_field("overrideSpecial", false),
result: o.get_field("result", true),
special: o.get_field("special", true),
upper: o.get_field("upper", true),
}
}
}
Expand All @@ -362,8 +362,8 @@ impl random_uuid::Guest for Component {
let o = register(&request);

random_uuid::Res {
keepers: o.get_field("keepers"),
result: o.get_field("result"),
keepers: o.get_field("keepers", false),
result: o.get_field("result", true),
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface output-interface {
constructor(value: list<u8>);
map: func(function-name: string) -> output;
get: func() -> option<list<u8>>;
get-field: func(field: string) -> output;
get-field: func(field: string, required: bool) -> output;
get-type: func() -> string;
duplicate: func() -> output;
}
Expand Down
Loading

0 comments on commit fa39f3e

Please sign in to comment.