Skip to content

Commit

Permalink
Add InvokeSingle variants to dotnet and nodejs SDKs
Browse files Browse the repository at this point in the history
  • Loading branch information
Zaid-Ajaj committed Dec 6, 2022
1 parent 9ba1830 commit 9b8b9a1
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 1 deletion.
29 changes: 29 additions & 0 deletions sdk/Pulumi/Deployment/DeploymentInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,22 @@ internal DeploymentInstance(IDeployment deployment)
public Output<T> Invoke<T>(string token, InvokeArgs args, InvokeOptions? options = null)
=> _deployment.Invoke<T>(token, args, options);

/// <summary>
/// Dynamically invokes the function '<paramref name="token"/>', which is offered by a
/// provider plugin.
/// <para/>
/// The result of <see cref="InvokeSingle"/> will be a <see cref="Output"/> resolved to the
/// result value of the provider plugin.
/// <para/>
/// Similar to the earlier <see cref="InvokeSingleAsync"/>, but supports passing input values
/// and returns an Output value.
/// <para/>
/// The <paramref name="args"/> inputs can be a bag of computed values(including, `T`s,
/// <see cref="Task{TResult}"/>s, <see cref="Output{T}"/>s etc.).
/// </summary>
public Output<T> InvokeSingle<T>(string token, InvokeArgs args, InvokeOptions? options = null)
=> _deployment.InvokeSingle<T>(token, args, options);

/// <summary>
/// Dynamically invokes the function '<paramref name="token"/>', which is offered by a
/// provider plugin.
Expand All @@ -63,6 +79,19 @@ public Output<T> Invoke<T>(string token, InvokeArgs args, InvokeOptions? options
public Task<T> InvokeAsync<T>(string token, InvokeArgs args, InvokeOptions? options = null)
=> _deployment.InvokeAsync<T>(token, args, options);

/// <summary>
/// Dynamically invokes the function '<paramref name="token"/>', which is offered by a
/// provider plugin.
/// <para/>
/// The result of <see cref="InvokeSingleAsync"/> will be a <see cref="Task"/> resolved to the
/// result value of the provider plugin which is expected to be a dictionary with single value.
/// <para/>
/// The <paramref name="args"/> inputs can be a bag of computed values(including, `T`s,
/// <see cref="Task{TResult}"/>s, <see cref="Output{T}"/>s etc.).
/// </summary>
public Task<T> InvokeSingleAsync<T>(string token, InvokeArgs args, InvokeOptions? options = null)
=> _deployment.InvokeSingleAsync<T>(token, args, options);

/// <summary>
/// Same as <see cref="InvokeAsync{T}(string, InvokeArgs, InvokeOptions)"/>, however the
/// return value is ignored.
Expand Down
13 changes: 13 additions & 0 deletions sdk/Pulumi/Deployment/Deployment_Invoke.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2016-2021, Pulumi Corporation

using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Threading.Tasks;
Expand All @@ -18,9 +19,21 @@ Task IDeployment.InvokeAsync(string token, InvokeArgs args, InvokeOptions? optio
Task<T> IDeployment.InvokeAsync<T>(string token, InvokeArgs args, InvokeOptions? options)
=> InvokeAsync<T>(token, args, options, convertResult: true);

async Task<T> IDeployment.InvokeSingleAsync<T>(string token, InvokeArgs args, InvokeOptions? options)
{
var outputs = await InvokeAsync<Dictionary<string, T>>(token, args, options, convertResult: true);
return outputs.Values.First();
}

Output<T> IDeployment.Invoke<T>(string token, InvokeArgs args, InvokeOptions? options)
=> new Output<T>(RawInvoke<T>(token, args, options));

Output<T> IDeployment.InvokeSingle<T>(string token, InvokeArgs args, InvokeOptions? options)
{
var outputResult = new Output<Dictionary<string, T>>(RawInvoke<Dictionary<string, T>>(token, args, options));
return outputResult.Apply(outputs => outputs.Values.First());
}

private async Task<OutputData<T>> RawInvoke<T>(string token, InvokeArgs args, InvokeOptions? options)
{
// This method backs all `Fn.Invoke()` calls that generate
Expand Down
24 changes: 24 additions & 0 deletions sdk/Pulumi/Deployment/IDeployment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ internal interface IDeployment
/// </summary>
Task<T> InvokeAsync<T>(string token, InvokeArgs args, InvokeOptions? options = null);

/// <summary>
/// Dynamically invokes the function '<paramref name="token"/>', which is offered by a
/// provider plugin.
/// <para/>
/// The result of <see cref="InvokeSingleAsync"/> will be a <see cref="Task"/> resolved to the
/// result value of the provider plugin that returns a bag of properties with a single value that is returned.
/// <para/>
/// The <paramref name="args"/> inputs can be a bag of computed values(including, `T`s,
/// <see cref="Task{TResult}"/>s, <see cref="Output{T}"/>s etc.).
/// </summary>
Task<T> InvokeSingleAsync<T>(string token, InvokeArgs args, InvokeOptions? options = null);

/// <summary>
/// Dynamically invokes the function '<paramref name="token"/>', which is offered by a
/// provider plugin.
Expand All @@ -50,6 +62,18 @@ internal interface IDeployment
/// </summary>
Output<T> Invoke<T>(string token, InvokeArgs args, InvokeOptions? options = null);

/// <summary>
/// Dynamically invokes the function '<paramref name="token"/>', which is offered by a
/// provider plugin.
/// <para/>
/// The result of <see cref="InvokeSingle"/> will be a <see cref="Output"/> resolved to the
/// result value of the provider plugin that returns a bag of properties with a single value that is returned.
/// <para/>
/// The <paramref name="args"/> inputs can be a bag of computed values(including, `T`s,
/// <see cref="Task{TResult}"/>s, <see cref="Output{T}"/>s etc.).
/// </summary>
Output<T> InvokeSingle<T>(string token, InvokeArgs args, InvokeOptions? options = null);

/// <summary>
/// Same as <see cref="InvokeAsync{T}(string, InvokeArgs, InvokeOptions)"/>, however the
/// return value is ignored.
Expand Down
4 changes: 3 additions & 1 deletion sdk/Pulumi/PublicAPI.Shipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ Pulumi.DeploymentInstance.Call(string token, Pulumi.CallArgs args, Pulumi.Resour
Pulumi.DeploymentInstance.Call<T>(string token, Pulumi.CallArgs args, Pulumi.Resource self = null, Pulumi.CallOptions options = null) -> Pulumi.Output<T>
Pulumi.DeploymentInstance.InvokeAsync(string token, Pulumi.InvokeArgs args, Pulumi.InvokeOptions options = null) -> System.Threading.Tasks.Task
Pulumi.DeploymentInstance.InvokeAsync<T>(string token, Pulumi.InvokeArgs args, Pulumi.InvokeOptions options = null) -> System.Threading.Tasks.Task<T>
Pulumi.DeploymentInstance.InvokeSingleAsync<T>(string token, Pulumi.InvokeArgs args, Pulumi.InvokeOptions options = null) -> System.Threading.Tasks.Task<T>
Pulumi.DeploymentInstance.IsDryRun.get -> bool
Pulumi.DeploymentInstance.ProjectName.get -> string
Pulumi.DeploymentInstance.StackName.get -> string
Expand Down Expand Up @@ -395,4 +396,5 @@ static Pulumi.Urn.Create(Pulumi.Input<string> name, Pulumi.Input<string> type, P
static readonly Pulumi.CallArgs.Empty -> Pulumi.CallArgs
static readonly Pulumi.InvokeArgs.Empty -> Pulumi.InvokeArgs
static readonly Pulumi.ResourceArgs.Empty -> Pulumi.ResourceArgs
Pulumi.DeploymentInstance.Invoke<T>(string token, Pulumi.InvokeArgs args, Pulumi.InvokeOptions options = null) -> Pulumi.Output<T>
Pulumi.DeploymentInstance.Invoke<T>(string token, Pulumi.InvokeArgs args, Pulumi.InvokeOptions options = null) -> Pulumi.Output<T>
Pulumi.DeploymentInstance.InvokeSingle<T>(string token, Pulumi.InvokeArgs args, Pulumi.InvokeOptions options = null) -> Pulumi.Output<T>

0 comments on commit 9b8b9a1

Please sign in to comment.