Serialize opts

This commit is contained in:
Luke Hoban 2019-12-28 20:31:33 -08:00 committed by Pat Gavlin
parent b37e47f46f
commit 51adc500de
6 changed files with 22 additions and 12 deletions

View file

@ -1,9 +1,11 @@
TODO:
- [ ] Serialize `opts` through to remote process
- [x] Serialize `opts` through to remote process
- [x] Support `ComponentResource`s as outputs
- [x] Support `CustomResource`s as outputs
- [ ] Support `ComponentResource`s as inputs
- [ ] Support `CustomResource`s as inputs
- [ ] Support `provider`/`providers` opts (ProviderResource hydration)
- [ ] Support `parent` opts (hydration of arbitrary Resources, even if no proxy exists?)
- [ ] First class `Resource` on RPC (instead of string matching `urn:pulumi` )
- [ ] Real multi-lang: replace `remote.construct` with an engine invoke (or RPC) that spwans
language host, loads the requested module, evals the requested constructor, returns back the URN.

View file

@ -9,8 +9,8 @@ pulumi.runtime.registerProxyConstructor("aws:ec2/securityGroup:SecurityGroup", a
// This is code the user would write to use `mycomponent` from the guest language.
const res = new mycomponent.MyComponent("n", {
input1: Promise.resolve(24),
});
input1: Promise.resolve(42),
}, { ignoreChanges: ["input1"] /*, providers: { "aws": awsProvider } */ });
export const id2 = res.myid;
export const output1 = res.output1;

View file

@ -1,6 +1,12 @@
const pulumi = require("@pulumi/pulumi");
const aws = require("@pulumi/aws");
// TODO: This should be done in the AWS library. Also, not clear that providers work correctly
// currently - we appear to end up with class to `Check` a provider before it has been configured -
// I suspect that the proxy is getting confused as a separate identity even though it's the same
// URN.
pulumi.runtime.registerProxyConstructor("pulumi:providers:aws", aws.Provider)
class MyInnerComponent extends pulumi.ComponentResource {
constructor(name, args, opts) {
super("my:mod:MyInnerComponent", name, {}, opts);

View file

@ -36,7 +36,6 @@ export interface MyComponentArgs {
input1: pulumi.Input<number>;
}
export class MyComponent extends pulumi.ComponentResource {
public myid!: pulumi.Output<string>;
public output1!: pulumi.Output<number>;
@ -51,7 +50,7 @@ export class MyComponent extends pulumi.ComponentResource {
// proxy from that URN.
if (!opts.urn) {
// TODO: Serialize `opts` to the remote construct
const p = remote.construct("./mycomponent", "MyComponent", name, args /*, opts */);
const p = remote.construct("./mycomponent", "MyComponent", name, args, opts);
const urn = p.then(r => <string>r.urn);
opts = pulumi.mergeOptions(opts, { urn });
}

View file

@ -13,9 +13,12 @@ const gstruct = require("google-protobuf/google/protobuf/struct_pb.js");
// (8) returning these asynchronously to the caller. The result is a flat JSON object representing
// the resources properties, which can be used to populate `Ouput`-typed properties on a proxy
// `Resource` object.
export async function construct(libraryPath: string, resource: string, name: string, args: any): Promise<any> {
const resolved = await pulumi.runtime.serializeProperties("construct", args);
const outputsObj = gstruct.Struct.fromJavaScript(resolved);
export async function construct(libraryPath: string, resource: string, name: string, args: any, opts?: any): Promise<any> {
const serializedArgs = await pulumi.runtime.serializeProperties("construct-args", args);
const argsStruct = gstruct.Struct.fromJavaScript(serializedArgs);
const serializedOpts = await pulumi.runtime.serializeProperties("construct-opts", opts);
const optsStruct = gstruct.Struct.fromJavaScript(serializedOpts);
let doneResolver: (value?: any) => void;
let doneRejecter: (reason?: any) => void;
@ -25,7 +28,8 @@ export async function construct(libraryPath: string, resource: string, name: str
require: require,
console: console,
_libraryPath: libraryPath,
_argsStruct: outputsObj,
_argsStruct: argsStruct,
_optsStruct: optsStruct,
_res: resource,
_name: name,
_doneResolver: doneResolver!,
@ -38,9 +42,9 @@ export async function construct(libraryPath: string, resource: string, name: str
var gstruct = require("google-protobuf/google/protobuf/struct_pb.js");
var library = require(_libraryPath)
var args = pulumi.runtime.deserializeProperties(_argsStruct);
const res = new (library[_res])(_name, args);
var opts = pulumi.runtime.deserializeProperties(_optsStruct);
const res = new (library[_res])(_name, args, opts);
return pulumi.runtime.serializeProperties("inner-construct", res).then(resolved => {
//console.log(resolved);
return gstruct.Struct.fromJavaScript(resolved);
}).then(_doneResolver, _doneRejecter);
})()

View file

@ -3,7 +3,6 @@
"align": [
true,
"parameters",
"arguments",
"statements"
],
"ban": false,