From fa39f3ed217cfc8234173fe5802f6bea18e49cd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=8BAndrzej=20Ressel?= Date: Tue, 2 Apr 2024 01:04:52 +0200 Subject: [PATCH] Support optional result fields (#96) --- examples/simple/justfile | 7 + examples/simple/src/lib.rs | 4 + examples/simple/tests/test.rs | 7 + .../src/bindings.rs | 130 ++++++++++-------- .../pulumi_wasm_provider_random/src/lib.rs | 108 +++++++-------- .../wit/deps/pulumi-wasm.wit | 2 +- .../src/source.rs | 128 ++++++++--------- .../wit/deps/pulumi-wasm.wit | 2 +- pulumi_wasm/src/bindings.rs | 53 +++---- pulumi_wasm/src/finalizer.rs | 9 +- pulumi_wasm/src/lib.rs | 35 ++--- pulumi_wasm/src/output.rs | 7 +- pulumi_wasm/tests/test.rs | 63 ++++++--- .../src/output/provider/lib.rs.handlebars | 2 +- .../src/output/provider/source_code.rs | 2 + .../src/output/wit/dependencies.wit | 2 +- pulumi_wasm_generator/src/schema.rs | 4 +- .../output/random_provider/lib/src/source.rs | 128 ++++++++--------- .../lib/wit/deps/pulumi-wasm.wit | 2 +- .../random_provider/provider/src/bindings.rs | 130 ++++++++++-------- .../random_provider/provider/src/lib.rs | 108 +++++++-------- .../provider/wit/deps/pulumi-wasm.wit | 2 +- wits/world.wit | 2 +- 23 files changed, 503 insertions(+), 434 deletions(-) diff --git a/examples/simple/justfile b/examples/simple/justfile index 2a3783092..a61b03253 100644 --- a/examples/simple/justfile +++ b/examples/simple/justfile @@ -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 \ No newline at end of file diff --git a/examples/simple/src/lib.rs b/examples/simple/src/lib.rs index 6369f078f..0f989a056 100644 --- a/examples/simple/src/lib.rs +++ b/examples/simple/src/lib.rs @@ -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(()) } diff --git a/examples/simple/tests/test.rs b/examples/simple/tests/test.rs index 90167239f..a3be044d4 100644 --- a/examples/simple/tests/test.rs +++ b/examples/simple/tests/test.rs @@ -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(()) } diff --git a/providers/pulumi_wasm_provider_random/src/bindings.rs b/providers/pulumi_wasm_provider_random/src/bindings.rs index 837237d18..85f289db6 100644 --- a/providers/pulumi_wasm_provider_random/src/bindings.rs +++ b/providers/pulumi_wasm_provider_random/src/bindings.rs @@ -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::(); @@ -197,14 +197,22 @@ pub mod component { #[link(wasm_import_module = "component:pulumi-wasm/output-interface@0.1.0")] 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) } } @@ -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/output-interface@0.1.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/register-interface@0.1.0\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/random-bytes@4.15.0\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/random-id@4.15.0\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/random-integer@4.15.0\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/random-password@4.15.0\ -\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/random-pet@4.15.0\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/random-shuffle@4.15.0\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/random-string@4.15.0\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/random-uuid@4.15.\ -0\x05\x0a\x04\x01\x1fpulumi:random/main-world@4.15.0\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/output-interface@0.1\ +.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/register-interface@0.1.0\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/random-bytes@4.15.0\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/random-id@4.15.0\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/random-integer@4.15.0\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/random-password@4.15.0\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/random-pet@4.15.0\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/random-shuffle@4.15.0\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/random-string@4.15.0\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/random-uuid@4.15.0\x05\x0a\x04\x01\x1fpulumi:random/main-world@4.15.0\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)] diff --git a/providers/pulumi_wasm_provider_random/src/lib.rs b/providers/pulumi_wasm_provider_random/src/lib.rs index 15c025398..66e39171a 100644 --- a/providers/pulumi_wasm_provider_random/src/lib.rs +++ b/providers/pulumi_wasm_provider_random/src/lib.rs @@ -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), } } } @@ -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), } } } @@ -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), } } } @@ -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), } } } @@ -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), } } } @@ -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), } } } @@ -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), } } } @@ -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), } } } diff --git a/providers/pulumi_wasm_provider_random/wit/deps/pulumi-wasm.wit b/providers/pulumi_wasm_provider_random/wit/deps/pulumi-wasm.wit index c5fabe8ce..1fe672b9d 100644 --- a/providers/pulumi_wasm_provider_random/wit/deps/pulumi-wasm.wit +++ b/providers/pulumi_wasm_provider_random/wit/deps/pulumi-wasm.wit @@ -9,7 +9,7 @@ interface output-interface { constructor(value: list); map: func(function-name: string) -> output; get: func() -> option>; - get-field: func(field: string) -> output; + get-field: func(field: string, required: bool) -> output; get-type: func() -> string; duplicate: func() -> output; } diff --git a/providers/pulumi_wasm_provider_random_rust/src/source.rs b/providers/pulumi_wasm_provider_random_rust/src/source.rs index 5a5ca2642..e8682ee7d 100644 --- a/providers/pulumi_wasm_provider_random_rust/src/source.rs +++ b/providers/pulumi_wasm_provider_random_rust/src/source.rs @@ -7,8 +7,8 @@ pub mod random_bytes { } pub struct RandomBytesResult { - pub base64: pulumi_wasm_rust::Output>, - pub hex: pulumi_wasm_rust::Output>, + pub base64: pulumi_wasm_rust::Output, + pub hex: pulumi_wasm_rust::Output, pub keepers: pulumi_wasm_rust::Output>>, pub length: pulumi_wasm_rust::Output, } @@ -25,8 +25,8 @@ pub mod random_bytes { ); RandomBytesResult { - base64: crate::random_to_domain_mapper::>(result.base64), - hex: crate::random_to_domain_mapper::>(result.hex), + base64: crate::random_to_domain_mapper::(result.base64), + hex: crate::random_to_domain_mapper::(result.hex), keepers: crate::random_to_domain_mapper::< Option>, >(result.keepers), @@ -45,11 +45,11 @@ pub mod random_id { } pub struct RandomIdResult { - pub b64_std: pulumi_wasm_rust::Output>, - pub b64_url: pulumi_wasm_rust::Output>, + pub b64_std: pulumi_wasm_rust::Output, + pub b64_url: pulumi_wasm_rust::Output, pub byte_length: pulumi_wasm_rust::Output, - pub dec: pulumi_wasm_rust::Output>, - pub hex: pulumi_wasm_rust::Output>, + pub dec: pulumi_wasm_rust::Output, + pub hex: pulumi_wasm_rust::Output, pub keepers: pulumi_wasm_rust::Output>>, pub prefix: pulumi_wasm_rust::Output>, } @@ -67,11 +67,11 @@ pub mod random_id { ); RandomIdResult { - b64_std: crate::random_to_domain_mapper::>(result.b64_std), - b64_url: crate::random_to_domain_mapper::>(result.b64_url), + b64_std: crate::random_to_domain_mapper::(result.b64_std), + b64_url: crate::random_to_domain_mapper::(result.b64_url), byte_length: crate::random_to_domain_mapper::(result.byte_length), - dec: crate::random_to_domain_mapper::>(result.dec), - hex: crate::random_to_domain_mapper::>(result.hex), + dec: crate::random_to_domain_mapper::(result.dec), + hex: crate::random_to_domain_mapper::(result.hex), keepers: crate::random_to_domain_mapper::< Option>, >(result.keepers), @@ -94,7 +94,7 @@ pub mod random_integer { pub keepers: pulumi_wasm_rust::Output>>, pub max: pulumi_wasm_rust::Output, pub min: pulumi_wasm_rust::Output, - pub result: pulumi_wasm_rust::Output>, + pub result: pulumi_wasm_rust::Output, pub seed: pulumi_wasm_rust::Output>, } @@ -117,7 +117,7 @@ pub mod random_integer { >(result.keepers), max: crate::random_to_domain_mapper::(result.max), min: crate::random_to_domain_mapper::(result.min), - result: crate::random_to_domain_mapper::>(result.result), + result: crate::random_to_domain_mapper::(result.result), seed: crate::random_to_domain_mapper::>(result.seed), } } @@ -142,20 +142,20 @@ pub mod random_password { } pub struct RandomPasswordResult { - pub bcrypt_hash: pulumi_wasm_rust::Output>, + pub bcrypt_hash: pulumi_wasm_rust::Output, pub keepers: pulumi_wasm_rust::Output>>, pub length: pulumi_wasm_rust::Output, - pub lower: pulumi_wasm_rust::Output>, - pub min_lower: pulumi_wasm_rust::Output>, - pub min_numeric: pulumi_wasm_rust::Output>, - pub min_special: pulumi_wasm_rust::Output>, - pub min_upper: pulumi_wasm_rust::Output>, - pub number: pulumi_wasm_rust::Output>, - pub numeric: pulumi_wasm_rust::Output>, + pub lower: pulumi_wasm_rust::Output, + pub min_lower: pulumi_wasm_rust::Output, + pub min_numeric: pulumi_wasm_rust::Output, + pub min_special: pulumi_wasm_rust::Output, + pub min_upper: pulumi_wasm_rust::Output, + pub number: pulumi_wasm_rust::Output, + pub numeric: pulumi_wasm_rust::Output, pub override_special: pulumi_wasm_rust::Output>, - pub result: pulumi_wasm_rust::Output>, - pub special: pulumi_wasm_rust::Output>, - pub upper: pulumi_wasm_rust::Output>, + pub result: pulumi_wasm_rust::Output, + pub special: pulumi_wasm_rust::Output, + pub upper: pulumi_wasm_rust::Output, } pub fn random_password(args: RandomPasswordArgs) -> RandomPasswordResult { @@ -180,24 +180,24 @@ pub mod random_password { ); RandomPasswordResult { - bcrypt_hash: crate::random_to_domain_mapper::>(result.bcrypt_hash), + bcrypt_hash: crate::random_to_domain_mapper::(result.bcrypt_hash), keepers: crate::random_to_domain_mapper::< Option>, >(result.keepers), length: crate::random_to_domain_mapper::(result.length), - lower: crate::random_to_domain_mapper::>(result.lower), - min_lower: crate::random_to_domain_mapper::>(result.min_lower), - min_numeric: crate::random_to_domain_mapper::>(result.min_numeric), - min_special: crate::random_to_domain_mapper::>(result.min_special), - min_upper: crate::random_to_domain_mapper::>(result.min_upper), - number: crate::random_to_domain_mapper::>(result.number), - numeric: crate::random_to_domain_mapper::>(result.numeric), + lower: crate::random_to_domain_mapper::(result.lower), + min_lower: crate::random_to_domain_mapper::(result.min_lower), + min_numeric: crate::random_to_domain_mapper::(result.min_numeric), + min_special: crate::random_to_domain_mapper::(result.min_special), + min_upper: crate::random_to_domain_mapper::(result.min_upper), + number: crate::random_to_domain_mapper::(result.number), + numeric: crate::random_to_domain_mapper::(result.numeric), override_special: crate::random_to_domain_mapper::>( result.override_special, ), - result: crate::random_to_domain_mapper::>(result.result), - special: crate::random_to_domain_mapper::>(result.special), - upper: crate::random_to_domain_mapper::>(result.upper), + result: crate::random_to_domain_mapper::(result.result), + special: crate::random_to_domain_mapper::(result.special), + upper: crate::random_to_domain_mapper::(result.upper), } } } @@ -214,9 +214,9 @@ pub mod random_pet { pub struct RandomPetResult { pub keepers: pulumi_wasm_rust::Output>>, - pub length: pulumi_wasm_rust::Output>, + pub length: pulumi_wasm_rust::Output, pub prefix: pulumi_wasm_rust::Output>, - pub separator: pulumi_wasm_rust::Output>, + pub separator: pulumi_wasm_rust::Output, } pub fn random_pet(args: RandomPetArgs) -> RandomPetResult { @@ -236,9 +236,9 @@ pub mod random_pet { keepers: crate::random_to_domain_mapper::< Option>, >(result.keepers), - length: crate::random_to_domain_mapper::>(result.length), + length: crate::random_to_domain_mapper::(result.length), prefix: crate::random_to_domain_mapper::>(result.prefix), - separator: crate::random_to_domain_mapper::>(result.separator), + separator: crate::random_to_domain_mapper::(result.separator), } } } @@ -257,7 +257,7 @@ pub mod random_shuffle { pub inputs: pulumi_wasm_rust::Output>, pub keepers: pulumi_wasm_rust::Output>>, pub result_count: pulumi_wasm_rust::Output>, - pub results: pulumi_wasm_rust::Output>>, + pub results: pulumi_wasm_rust::Output>, pub seed: pulumi_wasm_rust::Output>, } @@ -280,7 +280,7 @@ pub mod random_shuffle { Option>, >(result.keepers), result_count: crate::random_to_domain_mapper::>(result.result_count), - results: crate::random_to_domain_mapper::>>(result.results), + results: crate::random_to_domain_mapper::>(result.results), seed: crate::random_to_domain_mapper::>(result.seed), } } @@ -307,17 +307,17 @@ pub mod random_string { pub struct RandomStringResult { pub keepers: pulumi_wasm_rust::Output>>, pub length: pulumi_wasm_rust::Output, - pub lower: pulumi_wasm_rust::Output>, - pub min_lower: pulumi_wasm_rust::Output>, - pub min_numeric: pulumi_wasm_rust::Output>, - pub min_special: pulumi_wasm_rust::Output>, - pub min_upper: pulumi_wasm_rust::Output>, - pub number: pulumi_wasm_rust::Output>, - pub numeric: pulumi_wasm_rust::Output>, + pub lower: pulumi_wasm_rust::Output, + pub min_lower: pulumi_wasm_rust::Output, + pub min_numeric: pulumi_wasm_rust::Output, + pub min_special: pulumi_wasm_rust::Output, + pub min_upper: pulumi_wasm_rust::Output, + pub number: pulumi_wasm_rust::Output, + pub numeric: pulumi_wasm_rust::Output, pub override_special: pulumi_wasm_rust::Output>, - pub result: pulumi_wasm_rust::Output>, - pub special: pulumi_wasm_rust::Output>, - pub upper: pulumi_wasm_rust::Output>, + pub result: pulumi_wasm_rust::Output, + pub special: pulumi_wasm_rust::Output, + pub upper: pulumi_wasm_rust::Output, } pub fn random_string(args: RandomStringArgs) -> RandomStringResult { @@ -346,19 +346,19 @@ pub mod random_string { Option>, >(result.keepers), length: crate::random_to_domain_mapper::(result.length), - lower: crate::random_to_domain_mapper::>(result.lower), - min_lower: crate::random_to_domain_mapper::>(result.min_lower), - min_numeric: crate::random_to_domain_mapper::>(result.min_numeric), - min_special: crate::random_to_domain_mapper::>(result.min_special), - min_upper: crate::random_to_domain_mapper::>(result.min_upper), - number: crate::random_to_domain_mapper::>(result.number), - numeric: crate::random_to_domain_mapper::>(result.numeric), + lower: crate::random_to_domain_mapper::(result.lower), + min_lower: crate::random_to_domain_mapper::(result.min_lower), + min_numeric: crate::random_to_domain_mapper::(result.min_numeric), + min_special: crate::random_to_domain_mapper::(result.min_special), + min_upper: crate::random_to_domain_mapper::(result.min_upper), + number: crate::random_to_domain_mapper::(result.number), + numeric: crate::random_to_domain_mapper::(result.numeric), override_special: crate::random_to_domain_mapper::>( result.override_special, ), - result: crate::random_to_domain_mapper::>(result.result), - special: crate::random_to_domain_mapper::>(result.special), - upper: crate::random_to_domain_mapper::>(result.upper), + result: crate::random_to_domain_mapper::(result.result), + special: crate::random_to_domain_mapper::(result.special), + upper: crate::random_to_domain_mapper::(result.upper), } } } @@ -372,7 +372,7 @@ pub mod random_uuid { pub struct RandomUuidResult { pub keepers: pulumi_wasm_rust::Output>>, - pub result: pulumi_wasm_rust::Output>, + pub result: pulumi_wasm_rust::Output, } pub fn random_uuid(args: RandomUuidArgs) -> RandomUuidResult { @@ -389,7 +389,7 @@ pub mod random_uuid { keepers: crate::random_to_domain_mapper::< Option>, >(result.keepers), - result: crate::random_to_domain_mapper::>(result.result), + result: crate::random_to_domain_mapper::(result.result), } } } diff --git a/providers/pulumi_wasm_provider_random_rust/wit/deps/pulumi-wasm.wit b/providers/pulumi_wasm_provider_random_rust/wit/deps/pulumi-wasm.wit index c5fabe8ce..1fe672b9d 100644 --- a/providers/pulumi_wasm_provider_random_rust/wit/deps/pulumi-wasm.wit +++ b/providers/pulumi_wasm_provider_random_rust/wit/deps/pulumi-wasm.wit @@ -9,7 +9,7 @@ interface output-interface { constructor(value: list); map: func(function-name: string) -> output; get: func() -> option>; - get-field: func(field: string) -> output; + get-field: func(field: string, required: bool) -> output; get-type: func() -> string; duplicate: func() -> output; } diff --git a/pulumi_wasm/src/bindings.rs b/pulumi_wasm/src/bindings.rs index c17cfc59a..586aa763f 100644 --- a/pulumi_wasm/src/bindings.rs +++ b/pulumi_wasm/src/bindings.rs @@ -569,12 +569,14 @@ pub mod exports { arg0: i32, arg1: *mut u8, arg2: usize, + arg3: i32, ) -> i32 { let len0 = arg2; let bytes0 = _rt::Vec::from_raw_parts(arg1.cast(), len0, len0); let result1 = T::get_field( OutputBorrow::lift(arg0 as u32 as usize).get(), _rt::string_lift(bytes0), + _rt::bool_lift(arg3 as u8), ); (result1).take_handle() as i32 } @@ -659,7 +661,7 @@ pub mod exports { fn new(value: _rt::Vec) -> Self; fn map(&self, function_name: _rt::String) -> Output; fn get(&self) -> Option<_rt::Vec>; - fn get_field(&self, field: _rt::String) -> Output; + fn get_field(&self, field: _rt::String, required: bool) -> Output; fn get_type(&self) -> _rt::String; fn duplicate(&self) -> Output; } @@ -697,8 +699,8 @@ pub mod exports { $($path_to_types)*::__post_return_method_output_get::<<$ty as $($path_to_types)*::Guest>::Output>(arg0) } #[export_name = "component:pulumi-wasm/output-interface@0.1.0#[method]output.get-field"] - unsafe extern "C" fn export_method_output_get_field(arg0: i32,arg1: *mut u8,arg2: usize,) -> i32 { - $($path_to_types)*::_export_method_output_get_field_cabi::<<$ty as $($path_to_types)*::Guest>::Output>(arg0, arg1, arg2) + unsafe extern "C" fn export_method_output_get_field(arg0: i32,arg1: *mut u8,arg2: usize,arg3: i32,) -> i32 { + $($path_to_types)*::_export_method_output_get_field_cabi::<<$ty as $($path_to_types)*::Guest>::Output>(arg0, arg1, arg2, arg3) } #[export_name = "component:pulumi-wasm/output-interface@0.1.0#[method]output.get-type"] unsafe extern "C" fn export_method_output_get_type(arg0: i32,) -> *mut u8 { @@ -1268,8 +1270,8 @@ pub(crate) use __export_pulumi_wasm_impl as export; #[cfg(target_arch = "wasm32")] #[link_section = "component-type:wit-bindgen:0.21.0:pulumi-wasm:encoded world"] #[doc(hidden)] -pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 1499] = *b"\ -\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\xd9\x0a\x01A\x02\x01\ +pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 1509] = *b"\ +\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\xe3\x0a\x01A\x02\x01\ A\x0d\x01B\x0a\x01m\x05\x05TRACE\x05DEBUG\x04INFO\x04WARN\x05ERROR\x04\0\x05leve\ l\x03\0\0\x01ks\x01ky\x01o\x02ss\x01p\x04\x01r\x07\x05level\x01\x06targets\x04ar\ gss\x0bmodule-path\x02\x04file\x02\x04line\x03\x0akey-values\x05\x04\0\x07conten\ @@ -1281,26 +1283,27 @@ ent:pulumi-wasm/log@0.1.0\x05\0\x01B\x08\x01@\0\0\x7f\x04\0\x0dis-in-preview\x01 \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\x04se\ -lf\x04\0\x02\x04\0\x18[method]output.duplicate\x01\x0a\x01@\0\0s\x04\0\x10descri\ -be-outputs\x01\x0b\x01@\0\0\x7f\x04\0\x0fnon-done-exists\x01\x0c\x04\x01,compone\ -nt:pulumi-wasm/output-interface@0.1.0\x05\x02\x02\x03\0\x02\x06output\x01B\x0b\x02\ -\x03\x02\x01\x03\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\x04\x01.component:pulumi-wasm/register-interface@\ -0.1.0\x05\x04\x01B\x0f\x02\x03\x02\x01\x03\x04\0\x06output\x03\0\0\x01i\x01\x01p\ -}\x01r\x03\x02id\x02\x0bfunction-ids\x05value\x03\x04\0\x1bfunction-invocation-r\ -equest\x03\0\x04\x01h\x01\x01r\x02\x02id\x06\x05value\x03\x04\0\x1afunction-invo\ -cation-result\x03\0\x07\x01p\x05\x01@\x01\x06sources\0\x09\x04\0\x0dget-function\ -s\x01\x0a\x01p\x08\x01@\x01\x07results\x0b\x01\0\x04\0\x0dset-functions\x01\x0c\x04\ -\x015component:pulumi-wasm/function-reverse-callback@0.1.0\x05\x05\x01B\x07\x02\x03\ -\x02\x01\x03\x04\0\x06output\x03\0\0\x01h\x01\x01@\x02\x04names\x05value\x02\x01\ -\0\x04\0\x0aadd-export\x01\x03\x01@\0\0\x7f\x04\0\x06finish\x01\x04\x04\x01+comp\ -onent:pulumi-wasm/stack-interface@0.1.0\x05\x06\x04\x01'component:pulumi-wasm/pu\ -lumi-wasm@0.1.0\x04\0\x0b\x11\x01\0\x0bpulumi-wasm\x03\0\0\0G\x09producers\x01\x0c\ -processed-by\x02\x0dwit-component\x070.201.0\x10wit-bindgen-rust\x060.21.0"; +\x07\x01@\x03\x04self\x04\x05fields\x08required\x7f\0\x02\x04\0\x18[method]outpu\ +t.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\ +\x04\x01,component:pulumi-wasm/output-interface@0.1.0\x05\x02\x02\x03\0\x02\x06o\ +utput\x01B\x0b\x02\x03\x02\x01\x03\x04\0\x06output\x03\0\0\x01h\x01\x01r\x02\x04\ +names\x05value\x02\x04\0\x0cobject-field\x03\0\x03\x01p\x04\x01r\x03\x04types\x04\ +names\x06object\x05\x04\0\x19register-resource-request\x03\0\x06\x01i\x01\x01@\x01\ +\x07request\x07\0\x08\x04\0\x08register\x01\x09\x04\x01.component:pulumi-wasm/re\ +gister-interface@0.1.0\x05\x04\x01B\x0f\x02\x03\x02\x01\x03\x04\0\x06output\x03\0\ +\0\x01i\x01\x01p}\x01r\x03\x02id\x02\x0bfunction-ids\x05value\x03\x04\0\x1bfunct\ +ion-invocation-request\x03\0\x04\x01h\x01\x01r\x02\x02id\x06\x05value\x03\x04\0\x1a\ +function-invocation-result\x03\0\x07\x01p\x05\x01@\x01\x06sources\0\x09\x04\0\x0d\ +get-functions\x01\x0a\x01p\x08\x01@\x01\x07results\x0b\x01\0\x04\0\x0dset-functi\ +ons\x01\x0c\x04\x015component:pulumi-wasm/function-reverse-callback@0.1.0\x05\x05\ +\x01B\x07\x02\x03\x02\x01\x03\x04\0\x06output\x03\0\0\x01h\x01\x01@\x02\x04names\ +\x05value\x02\x01\0\x04\0\x0aadd-export\x01\x03\x01@\0\0\x7f\x04\0\x06finish\x01\ +\x04\x04\x01+component:pulumi-wasm/stack-interface@0.1.0\x05\x06\x04\x01'compone\ +nt:pulumi-wasm/pulumi-wasm@0.1.0\x04\0\x0b\x11\x01\0\x0bpulumi-wasm\x03\0\0\0G\x09\ +producers\x01\x0cprocessed-by\x02\x0dwit-component\x070.201.0\x10wit-bindgen-rus\ +t\x060.21.0"; #[inline(never)] #[doc(hidden)] diff --git a/pulumi_wasm/src/finalizer.rs b/pulumi_wasm/src/finalizer.rs index 84a742529..b3dcae3e6 100644 --- a/pulumi_wasm/src/finalizer.rs +++ b/pulumi_wasm/src/finalizer.rs @@ -4,7 +4,7 @@ use crate::output::{access_map, output_map, OutputContent}; use crate::{grpc, output}; use log::info; use prost::Message; -use rmpv::Value; + use std::ops::Deref; use std::sync::atomic::AtomicBool; use std::sync::atomic::Ordering::Relaxed; @@ -51,7 +51,7 @@ fn invoke_exporting_if_needed() { }; info!("Request: [{request:?}]"); external_world::register_resource_outputs(request.encode_to_vec().as_slice()); - Value::Nil + None }, ); } @@ -101,7 +101,10 @@ fn combine_outputs() -> bool { None => {} Some(i) => { changed = true; - o.replace(OutputContent::Done(i)); + match i { + None => o.replace(OutputContent::Nothing), + Some(i) => o.replace(OutputContent::Done(i)), + }; } }; }); diff --git a/pulumi_wasm/src/lib.rs b/pulumi_wasm/src/lib.rs index df85bc2db..703a1d2b1 100644 --- a/pulumi_wasm/src/lib.rs +++ b/pulumi_wasm/src/lib.rs @@ -1,3 +1,4 @@ +use crate::bindings::component::pulumi_wasm::external_world::is_in_preview; use crate::bindings::exports::component::pulumi_wasm::function_reverse_callback::{ FunctionInvocationRequest, FunctionInvocationResult, }; @@ -136,7 +137,7 @@ impl GuestOutput for Output { } } - fn get_field(&self, field: String) -> WasmOutput { + fn get_field(&self, field: String, required: bool) -> WasmOutput { wasm_common::setup_logger(); info!("Getting field [{field}] from Output [TODO]"); @@ -150,30 +151,22 @@ impl GuestOutput for Output { let key = Value::String(Utf8String::from(field.clone())); let maybe_value = m.iter().find(|(k, _)| k == &key).map(|(_, v)| v.clone()); //.unwrap_or(Value::Nil) match maybe_value { - None => { - // TODO: Implement - Value::Nil - // if is_in_preview() { - // Value::Nil - // } else { - // todo!() - // } + None if is_in_preview() => None, + None if required => { + error!("Field [{field}] not found in map [{m:?}]"); + unreachable!("Field [{field}] not found in map [{m:?}]") } - Some(v) => v, + None => Some(Value::Nil), + Some(v) => Some(v), } } - Value::Nil => todo!(), - Value::Boolean(_) => todo!(), - Value::Integer(_) => todo!(), - Value::F32(_) => todo!(), - Value::F64(_) => todo!(), - Value::String(_) => todo!(), - Value::Binary(_) => todo!(), - Value::Array(_) => todo!(), - Value::Ext(_, _) => todo!(), + v => { + error!("Value is not a map [{v}]"); + unreachable!("Value is not a map [{v}]") + } }; - info!("Result is [{v}]"); + info!("Result is [{v:?}]"); v }); @@ -395,7 +388,7 @@ impl register_interface::Guest for Component { info!("Message pack map: [{result:?}]"); - result + Some(result) }); WasmOutput::new(Output { diff --git a/pulumi_wasm/src/output.rs b/pulumi_wasm/src/output.rs index 43bdafe2e..6c5bcdc8d 100644 --- a/pulumi_wasm/src/output.rs +++ b/pulumi_wasm/src/output.rs @@ -70,7 +70,10 @@ pub(crate) fn output_map() -> &'static mut HashMap { pub(crate) enum OutputContent { Done(Value), Mapped(FunctionId, FunctionSource, OutputContentRefCell), - Func(Vec, Box) -> Value>), + Func( + Vec, + Box) -> Option>, + ), Nothing, } @@ -110,7 +113,7 @@ pub(crate) fn map_internal( f: F, ) -> Rc> where - F: Fn(Vec) -> Value + 'static, + F: Fn(Vec) -> Option + 'static, { create_wrapper(OutputContent::Func(ref_cell, Box::new(f))) } diff --git a/pulumi_wasm/tests/test.rs b/pulumi_wasm/tests/test.rs index 96a628cb8..43cd5ef58 100644 --- a/pulumi_wasm/tests/test.rs +++ b/pulumi_wasm/tests/test.rs @@ -161,8 +161,34 @@ fn should_return_value_of_handled_mapped_value() -> Result<(), Error> { } #[test] -fn should_return_uninitialized_when_getting_nonexisting_field_during_preview() -> Result<(), Error> -{ +fn should_panic_when_getting_nonexisting_required_field_not_during_preview() -> Result<(), Error> { + let (mut store, plugin) = create_engine(false)?; + + let output1 = plugin + .component_pulumi_wasm_output_interface() + .output() + .call_constructor( + &mut store, + rmp_serde::to_vec(&HashMap::from([("key", "value")])) + .unwrap() + .as_slice(), + )?; + + let _output2 = plugin + .component_pulumi_wasm_output_interface() + .output() + .call_get_field(&mut store, output1, "nonexisting", true)?; + + let result = run_loop(&mut store, &plugin); + + anyhow::ensure!(result.is_err()); + + Ok(()) +} + +#[test] +fn should_return_nothing_when_getting_nonexisting_nonrequired_field_during_preview( +) -> Result<(), Error> { let (mut store, plugin) = create_engine(true)?; let output1 = plugin @@ -178,7 +204,7 @@ fn should_return_uninitialized_when_getting_nonexisting_field_during_preview() - let output2 = plugin .component_pulumi_wasm_output_interface() .output() - .call_get_field(&mut store, output1, "nonexisting")?; + .call_get_field(&mut store, output1, "nonexisting", false)?; run_loop(&mut store, &plugin)?; @@ -187,21 +213,13 @@ fn should_return_uninitialized_when_getting_nonexisting_field_during_preview() - .output() .call_get_type(&mut store, output2)?; - let output2_value = plugin - .component_pulumi_wasm_output_interface() - .output() - .call_get(&mut store, output2)?; - - anyhow::ensure!(output2_type == "Done"); - anyhow::ensure!(output2_value.unwrap() == rmp_serde::to_vec(&None::).unwrap()); + anyhow::ensure!(output2_type == "Nothing"); Ok(()) } -//TODO: Implement #[test] -#[ignore] -fn should_panic_when_getting_nonexisting_field_not_during_preview() -> Result<(), Error> { +fn should_return_null_when_getting_nonexisting_nonrequired_field() -> Result<(), Error> { let (mut store, plugin) = create_engine(false)?; let output1 = plugin @@ -214,14 +232,25 @@ fn should_panic_when_getting_nonexisting_field_not_during_preview() -> Result<() .as_slice(), )?; - let _output2 = plugin + let output2 = plugin .component_pulumi_wasm_output_interface() .output() - .call_get_field(&mut store, output1, "nonexisting")?; + .call_get_field(&mut store, output1, "nonexisting", false)?; - let result = run_loop(&mut store, &plugin); + run_loop(&mut store, &plugin)?; - anyhow::ensure!(result.is_err()); + let output2_type = plugin + .component_pulumi_wasm_output_interface() + .output() + .call_get_type(&mut store, output2)?; + + let output2_value = plugin + .component_pulumi_wasm_output_interface() + .output() + .call_get(&mut store, output2)?; + + anyhow::ensure!(output2_type == "Done"); + anyhow::ensure!(output2_value.unwrap() == rmp_serde::to_vec(&None::).unwrap()); Ok(()) } diff --git a/pulumi_wasm_generator/src/output/provider/lib.rs.handlebars b/pulumi_wasm_generator/src/output/provider/lib.rs.handlebars index b16361749..da68bbc88 100644 --- a/pulumi_wasm_generator/src/output/provider/lib.rs.handlebars +++ b/pulumi_wasm_generator/src/output/provider/lib.rs.handlebars @@ -30,7 +30,7 @@ impl {{name}}::Guest for Component { {{name}}::Res { {{#each output_properties}} - {{arg_name}}: o.get_field("{{name}}"), + {{arg_name}}: o.get_field("{{name}}", {{required}}), {{/each}} } diff --git a/pulumi_wasm_generator/src/output/provider/source_code.rs b/pulumi_wasm_generator/src/output/provider/source_code.rs index 7e9d65987..8667f9d73 100644 --- a/pulumi_wasm_generator/src/output/provider/source_code.rs +++ b/pulumi_wasm_generator/src/output/provider/source_code.rs @@ -17,6 +17,7 @@ struct InputProperty { struct OutputProperty { name: String, arg_name: String, + required: bool, } #[derive(Serialize)] @@ -56,6 +57,7 @@ fn convert_model(package: &crate::model::Package) -> Package { .map(|output_property| OutputProperty { name: output_property.name.clone(), arg_name: create_valid_id(&output_property.name), + required: !matches!(output_property.r#type, crate::model::Type::Option(_)), }) .collect(), }) diff --git a/pulumi_wasm_generator/src/output/wit/dependencies.wit b/pulumi_wasm_generator/src/output/wit/dependencies.wit index c5fabe8ce..1fe672b9d 100644 --- a/pulumi_wasm_generator/src/output/wit/dependencies.wit +++ b/pulumi_wasm_generator/src/output/wit/dependencies.wit @@ -9,7 +9,7 @@ interface output-interface { constructor(value: list); map: func(function-name: string) -> output; get: func() -> option>; - get-field: func(field: string) -> output; + get-field: func(field: string, required: bool) -> output; get-type: func() -> string; duplicate: func() -> output; } diff --git a/pulumi_wasm_generator/src/schema.rs b/pulumi_wasm_generator/src/schema.rs index e3b2f016c..de5685de5 100644 --- a/pulumi_wasm_generator/src/schema.rs +++ b/pulumi_wasm_generator/src/schema.rs @@ -57,6 +57,8 @@ struct Resource { input_properties: PulumiMap, #[serde(default, rename = "requiredInputs")] required_inputs: BTreeSet, + #[serde(default)] + required: BTreeSet, } #[derive(Deserialize, Debug)] @@ -169,7 +171,7 @@ fn resource_to_model( .map(|(output_name, output_property)| { let mut type_ = new_type_mapper(&output_property.r#type) .context(format!("Cannot handle [{output_name}] type"))?; - if !resource.required_inputs.contains(output_name) { + if !resource.required.contains(output_name) { type_ = crate::model::Type::Option(Box::new(type_)); } Ok(crate::model::OutputProperty { diff --git a/pulumi_wasm_generator/tests/output/random_provider/lib/src/source.rs b/pulumi_wasm_generator/tests/output/random_provider/lib/src/source.rs index 4bb4495a4..f007ad957 100644 --- a/pulumi_wasm_generator/tests/output/random_provider/lib/src/source.rs +++ b/pulumi_wasm_generator/tests/output/random_provider/lib/src/source.rs @@ -8,8 +8,8 @@ pub mod random_bytes { } pub struct RandomBytesResult { - pub base64: pulumi_wasm_rust::Output>, - pub hex: pulumi_wasm_rust::Output>, + pub base64: pulumi_wasm_rust::Output, + pub hex: pulumi_wasm_rust::Output, pub keepers: pulumi_wasm_rust::Output>>, pub length: pulumi_wasm_rust::Output, } @@ -22,8 +22,8 @@ pub mod random_bytes { }); RandomBytesResult { - base64: crate::random_to_domain_mapper::>(result.base64), - hex: crate::random_to_domain_mapper::>(result.hex), + base64: crate::random_to_domain_mapper::(result.base64), + hex: crate::random_to_domain_mapper::(result.hex), keepers: crate::random_to_domain_mapper::>>(result.keepers), length: crate::random_to_domain_mapper::(result.length), } @@ -42,11 +42,11 @@ pub mod random_id { } pub struct RandomIdResult { - pub b64_std: pulumi_wasm_rust::Output>, - pub b64_url: pulumi_wasm_rust::Output>, + pub b64_std: pulumi_wasm_rust::Output, + pub b64_url: pulumi_wasm_rust::Output, pub byte_length: pulumi_wasm_rust::Output, - pub dec: pulumi_wasm_rust::Output>, - pub hex: pulumi_wasm_rust::Output>, + pub dec: pulumi_wasm_rust::Output, + pub hex: pulumi_wasm_rust::Output, pub keepers: pulumi_wasm_rust::Output>>, pub prefix: pulumi_wasm_rust::Output>, } @@ -60,11 +60,11 @@ pub mod random_id { }); RandomIdResult { - b64_std: crate::random_to_domain_mapper::>(result.b64_std), - b64_url: crate::random_to_domain_mapper::>(result.b64_url), + b64_std: crate::random_to_domain_mapper::(result.b64_std), + b64_url: crate::random_to_domain_mapper::(result.b64_url), byte_length: crate::random_to_domain_mapper::(result.byte_length), - dec: crate::random_to_domain_mapper::>(result.dec), - hex: crate::random_to_domain_mapper::>(result.hex), + dec: crate::random_to_domain_mapper::(result.dec), + hex: crate::random_to_domain_mapper::(result.hex), keepers: crate::random_to_domain_mapper::>>(result.keepers), prefix: crate::random_to_domain_mapper::>(result.prefix), } @@ -87,7 +87,7 @@ pub mod random_integer { pub keepers: pulumi_wasm_rust::Output>>, pub max: pulumi_wasm_rust::Output, pub min: pulumi_wasm_rust::Output, - pub result: pulumi_wasm_rust::Output>, + pub result: pulumi_wasm_rust::Output, pub seed: pulumi_wasm_rust::Output>, } @@ -104,7 +104,7 @@ pub mod random_integer { keepers: crate::random_to_domain_mapper::>>(result.keepers), max: crate::random_to_domain_mapper::(result.max), min: crate::random_to_domain_mapper::(result.min), - result: crate::random_to_domain_mapper::>(result.result), + result: crate::random_to_domain_mapper::(result.result), seed: crate::random_to_domain_mapper::>(result.seed), } } @@ -131,20 +131,20 @@ pub mod random_password { } pub struct RandomPasswordResult { - pub bcrypt_hash: pulumi_wasm_rust::Output>, + pub bcrypt_hash: pulumi_wasm_rust::Output, pub keepers: pulumi_wasm_rust::Output>>, pub length: pulumi_wasm_rust::Output, - pub lower: pulumi_wasm_rust::Output>, - pub min_lower: pulumi_wasm_rust::Output>, - pub min_numeric: pulumi_wasm_rust::Output>, - pub min_special: pulumi_wasm_rust::Output>, - pub min_upper: pulumi_wasm_rust::Output>, - pub number: pulumi_wasm_rust::Output>, - pub numeric: pulumi_wasm_rust::Output>, + pub lower: pulumi_wasm_rust::Output, + pub min_lower: pulumi_wasm_rust::Output, + pub min_numeric: pulumi_wasm_rust::Output, + pub min_special: pulumi_wasm_rust::Output, + pub min_upper: pulumi_wasm_rust::Output, + pub number: pulumi_wasm_rust::Output, + pub numeric: pulumi_wasm_rust::Output, pub override_special: pulumi_wasm_rust::Output>, - pub result: pulumi_wasm_rust::Output>, - pub special: pulumi_wasm_rust::Output>, - pub upper: pulumi_wasm_rust::Output>, + pub result: pulumi_wasm_rust::Output, + pub special: pulumi_wasm_rust::Output, + pub upper: pulumi_wasm_rust::Output, } pub fn random_password(args: RandomPasswordArgs) -> RandomPasswordResult { @@ -165,20 +165,20 @@ pub mod random_password { }); RandomPasswordResult { - bcrypt_hash: crate::random_to_domain_mapper::>(result.bcrypt_hash), + bcrypt_hash: crate::random_to_domain_mapper::(result.bcrypt_hash), keepers: crate::random_to_domain_mapper::>>(result.keepers), length: crate::random_to_domain_mapper::(result.length), - lower: crate::random_to_domain_mapper::>(result.lower), - min_lower: crate::random_to_domain_mapper::>(result.min_lower), - min_numeric: crate::random_to_domain_mapper::>(result.min_numeric), - min_special: crate::random_to_domain_mapper::>(result.min_special), - min_upper: crate::random_to_domain_mapper::>(result.min_upper), - number: crate::random_to_domain_mapper::>(result.number), - numeric: crate::random_to_domain_mapper::>(result.numeric), + lower: crate::random_to_domain_mapper::(result.lower), + min_lower: crate::random_to_domain_mapper::(result.min_lower), + min_numeric: crate::random_to_domain_mapper::(result.min_numeric), + min_special: crate::random_to_domain_mapper::(result.min_special), + min_upper: crate::random_to_domain_mapper::(result.min_upper), + number: crate::random_to_domain_mapper::(result.number), + numeric: crate::random_to_domain_mapper::(result.numeric), override_special: crate::random_to_domain_mapper::>(result.override_special), - result: crate::random_to_domain_mapper::>(result.result), - special: crate::random_to_domain_mapper::>(result.special), - upper: crate::random_to_domain_mapper::>(result.upper), + result: crate::random_to_domain_mapper::(result.result), + special: crate::random_to_domain_mapper::(result.special), + upper: crate::random_to_domain_mapper::(result.upper), } } @@ -197,9 +197,9 @@ pub mod random_pet { pub struct RandomPetResult { pub keepers: pulumi_wasm_rust::Output>>, - pub length: pulumi_wasm_rust::Output>, + pub length: pulumi_wasm_rust::Output, pub prefix: pulumi_wasm_rust::Output>, - pub separator: pulumi_wasm_rust::Output>, + pub separator: pulumi_wasm_rust::Output, } pub fn random_pet(args: RandomPetArgs) -> RandomPetResult { @@ -213,9 +213,9 @@ pub mod random_pet { RandomPetResult { keepers: crate::random_to_domain_mapper::>>(result.keepers), - length: crate::random_to_domain_mapper::>(result.length), + length: crate::random_to_domain_mapper::(result.length), prefix: crate::random_to_domain_mapper::>(result.prefix), - separator: crate::random_to_domain_mapper::>(result.separator), + separator: crate::random_to_domain_mapper::(result.separator), } } @@ -236,7 +236,7 @@ pub mod random_shuffle { pub inputs: pulumi_wasm_rust::Output>, pub keepers: pulumi_wasm_rust::Output>>, pub result_count: pulumi_wasm_rust::Output>, - pub results: pulumi_wasm_rust::Output>>, + pub results: pulumi_wasm_rust::Output>, pub seed: pulumi_wasm_rust::Output>, } @@ -253,7 +253,7 @@ pub mod random_shuffle { inputs: crate::random_to_domain_mapper::>(result.inputs), keepers: crate::random_to_domain_mapper::>>(result.keepers), result_count: crate::random_to_domain_mapper::>(result.result_count), - results: crate::random_to_domain_mapper::>>(result.results), + results: crate::random_to_domain_mapper::>(result.results), seed: crate::random_to_domain_mapper::>(result.seed), } } @@ -282,17 +282,17 @@ pub mod random_string { pub struct RandomStringResult { pub keepers: pulumi_wasm_rust::Output>>, pub length: pulumi_wasm_rust::Output, - pub lower: pulumi_wasm_rust::Output>, - pub min_lower: pulumi_wasm_rust::Output>, - pub min_numeric: pulumi_wasm_rust::Output>, - pub min_special: pulumi_wasm_rust::Output>, - pub min_upper: pulumi_wasm_rust::Output>, - pub number: pulumi_wasm_rust::Output>, - pub numeric: pulumi_wasm_rust::Output>, + pub lower: pulumi_wasm_rust::Output, + pub min_lower: pulumi_wasm_rust::Output, + pub min_numeric: pulumi_wasm_rust::Output, + pub min_special: pulumi_wasm_rust::Output, + pub min_upper: pulumi_wasm_rust::Output, + pub number: pulumi_wasm_rust::Output, + pub numeric: pulumi_wasm_rust::Output, pub override_special: pulumi_wasm_rust::Output>, - pub result: pulumi_wasm_rust::Output>, - pub special: pulumi_wasm_rust::Output>, - pub upper: pulumi_wasm_rust::Output>, + pub result: pulumi_wasm_rust::Output, + pub special: pulumi_wasm_rust::Output, + pub upper: pulumi_wasm_rust::Output, } pub fn random_string(args: RandomStringArgs) -> RandomStringResult { @@ -315,17 +315,17 @@ pub mod random_string { RandomStringResult { keepers: crate::random_to_domain_mapper::>>(result.keepers), length: crate::random_to_domain_mapper::(result.length), - lower: crate::random_to_domain_mapper::>(result.lower), - min_lower: crate::random_to_domain_mapper::>(result.min_lower), - min_numeric: crate::random_to_domain_mapper::>(result.min_numeric), - min_special: crate::random_to_domain_mapper::>(result.min_special), - min_upper: crate::random_to_domain_mapper::>(result.min_upper), - number: crate::random_to_domain_mapper::>(result.number), - numeric: crate::random_to_domain_mapper::>(result.numeric), + lower: crate::random_to_domain_mapper::(result.lower), + min_lower: crate::random_to_domain_mapper::(result.min_lower), + min_numeric: crate::random_to_domain_mapper::(result.min_numeric), + min_special: crate::random_to_domain_mapper::(result.min_special), + min_upper: crate::random_to_domain_mapper::(result.min_upper), + number: crate::random_to_domain_mapper::(result.number), + numeric: crate::random_to_domain_mapper::(result.numeric), override_special: crate::random_to_domain_mapper::>(result.override_special), - result: crate::random_to_domain_mapper::>(result.result), - special: crate::random_to_domain_mapper::>(result.special), - upper: crate::random_to_domain_mapper::>(result.upper), + result: crate::random_to_domain_mapper::(result.result), + special: crate::random_to_domain_mapper::(result.special), + upper: crate::random_to_domain_mapper::(result.upper), } } @@ -341,7 +341,7 @@ pub mod random_uuid { pub struct RandomUuidResult { pub keepers: pulumi_wasm_rust::Output>>, - pub result: pulumi_wasm_rust::Output>, + pub result: pulumi_wasm_rust::Output, } pub fn random_uuid(args: RandomUuidArgs) -> RandomUuidResult { @@ -352,7 +352,7 @@ pub mod random_uuid { RandomUuidResult { keepers: crate::random_to_domain_mapper::>>(result.keepers), - result: crate::random_to_domain_mapper::>(result.result), + result: crate::random_to_domain_mapper::(result.result), } } diff --git a/pulumi_wasm_generator/tests/output/random_provider/lib/wit/deps/pulumi-wasm.wit b/pulumi_wasm_generator/tests/output/random_provider/lib/wit/deps/pulumi-wasm.wit index c5fabe8ce..1fe672b9d 100644 --- a/pulumi_wasm_generator/tests/output/random_provider/lib/wit/deps/pulumi-wasm.wit +++ b/pulumi_wasm_generator/tests/output/random_provider/lib/wit/deps/pulumi-wasm.wit @@ -9,7 +9,7 @@ interface output-interface { constructor(value: list); map: func(function-name: string) -> output; get: func() -> option>; - get-field: func(field: string) -> output; + get-field: func(field: string, required: bool) -> output; get-type: func() -> string; duplicate: func() -> output; } diff --git a/pulumi_wasm_generator/tests/output/random_provider/provider/src/bindings.rs b/pulumi_wasm_generator/tests/output/random_provider/provider/src/bindings.rs index 837237d18..85f289db6 100644 --- a/pulumi_wasm_generator/tests/output/random_provider/provider/src/bindings.rs +++ b/pulumi_wasm_generator/tests/output/random_provider/provider/src/bindings.rs @@ -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::(); @@ -197,14 +197,22 @@ pub mod component { #[link(wasm_import_module = "component:pulumi-wasm/output-interface@0.1.0")] 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) } } @@ -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/output-interface@0.1.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/register-interface@0.1.0\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/random-bytes@4.15.0\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/random-id@4.15.0\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/random-integer@4.15.0\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/random-password@4.15.0\ -\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/random-pet@4.15.0\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/random-shuffle@4.15.0\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/random-string@4.15.0\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/random-uuid@4.15.\ -0\x05\x0a\x04\x01\x1fpulumi:random/main-world@4.15.0\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/output-interface@0.1\ +.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/register-interface@0.1.0\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/random-bytes@4.15.0\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/random-id@4.15.0\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/random-integer@4.15.0\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/random-password@4.15.0\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/random-pet@4.15.0\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/random-shuffle@4.15.0\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/random-string@4.15.0\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/random-uuid@4.15.0\x05\x0a\x04\x01\x1fpulumi:random/main-world@4.15.0\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)] diff --git a/pulumi_wasm_generator/tests/output/random_provider/provider/src/lib.rs b/pulumi_wasm_generator/tests/output/random_provider/provider/src/lib.rs index 39012ad21..d9e2b3290 100644 --- a/pulumi_wasm_generator/tests/output/random_provider/provider/src/lib.rs +++ b/pulumi_wasm_generator/tests/output/random_provider/provider/src/lib.rs @@ -32,10 +32,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), } } @@ -56,13 +56,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), } } @@ -84,11 +84,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), } } @@ -118,20 +118,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), } } @@ -153,10 +153,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), } } @@ -178,11 +178,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), } } @@ -212,19 +212,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), } } @@ -243,8 +243,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), } } diff --git a/pulumi_wasm_generator/tests/output/random_provider/provider/wit/deps/pulumi-wasm.wit b/pulumi_wasm_generator/tests/output/random_provider/provider/wit/deps/pulumi-wasm.wit index c5fabe8ce..1fe672b9d 100644 --- a/pulumi_wasm_generator/tests/output/random_provider/provider/wit/deps/pulumi-wasm.wit +++ b/pulumi_wasm_generator/tests/output/random_provider/provider/wit/deps/pulumi-wasm.wit @@ -9,7 +9,7 @@ interface output-interface { constructor(value: list); map: func(function-name: string) -> output; get: func() -> option>; - get-field: func(field: string) -> output; + get-field: func(field: string, required: bool) -> output; get-type: func() -> string; duplicate: func() -> output; } diff --git a/wits/world.wit b/wits/world.wit index 9552b17a7..0fa1a95d9 100644 --- a/wits/world.wit +++ b/wits/world.wit @@ -88,7 +88,7 @@ interface output-interface { constructor(value: list); map: func(function-name: string) -> output; get: func() -> option>; - get-field: func(field: string) -> output; + get-field: func(field: string, required: bool) -> output; get-type: func() -> string; duplicate: func() -> output; }