Compare commits

...

22 commits

Author SHA1 Message Date
Cyrus Najmabadi c6e7bc3c5d Merge branch 'revertChnage' into features/pojo 2019-02-23 19:41:08 -08:00
Cyrus Najmabadi c0f1eb1ed9 Revert "Simplify how we export the .all operator (#2467)"
This reverts commit 93c9464125.
2019-02-23 19:39:17 -08:00
Cyrus Najmabadi 01bc6ae2eb tuples vs non-tuples 2019-02-23 18:30:00 -08:00
Cyrus Najmabadi cdc196170c Do not distribute over union types 2019-02-23 17:49:49 -08:00
Cyrus Najmabadi 1830dd3b07 Don't touch resources. 2019-02-22 15:14:38 -08:00
Cyrus Najmabadi c2fd4d4ad4 Don't expand over undefined 2019-02-22 15:04:41 -08:00
Cyrus Najmabadi 334dca33fa Merge branch 'wrapping' into features/pojo 2019-02-22 13:39:48 -08:00
Cyrus Najmabadi daf05f3724 Add new way to express inputs to a resource. 2019-02-22 13:29:08 -08:00
Cyrus Najmabadi 613f07afb9 failure 2019-02-22 00:17:54 -08:00
Cyrus Najmabadi 892d902a80 Fix type 2019-02-21 22:01:59 -08:00
Cyrus Najmabadi 87201c0de2 Fix type 2019-02-21 21:59:39 -08:00
Cyrus Najmabadi 0c63fb1dba Different formalization 2019-02-21 21:51:41 -08:00
Cyrus Najmabadi aa0e66021a Different formalization 2019-02-21 21:49:38 -08:00
Cyrus Najmabadi 57484a58ac don't wrap functions 2019-02-21 20:44:16 -08:00
Cyrus Najmabadi 92488cc0c0 Merge remote-tracking branch 'origin/master' into features/pojo 2019-02-21 20:20:47 -08:00
Cyrus Najmabadi d732383861 delete line 2019-02-21 20:19:18 -08:00
Cyrus Najmabadi 16e80d5f42 Docs 2019-02-21 17:53:54 -08:00
Cyrus Najmabadi d0d0d54b44 lint 2019-02-21 17:37:08 -08:00
Cyrus Najmabadi 0f2a0d82e0 working booleans 2019-02-21 17:19:33 -08:00
Cyrus Najmabadi 4774eb76da more pojo work 2019-02-21 17:00:57 -08:00
Cyrus Najmabadi b86038489c Update changelog. 2019-02-21 14:36:02 -08:00
Cyrus Najmabadi ee4acd8c63 Simpler Input/Output model 2019-02-21 13:50:04 -08:00
2 changed files with 69 additions and 7 deletions

View file

@ -2,8 +2,9 @@
### Improvements
- Signature of `Pulumi.all` has been made more accurate. Calling `.all` on `Output`s that may
be `undefined` will properly encode and pass along that `undefined` information.
- Simplify how the args for a resource can be specified. Note: resource args are now simple POJO
types. To indicate the same type, except with `Input`s allows for all values, use
`WrappedObject<OriginalType>`.
## 0.16.15 (Released February 22nd, 2019)
@ -18,6 +19,7 @@
This will help out the programming model for Component Resources as your consumers can just
depend on a Component and have that automatically depend on all the child Resources created
by that Component.
- Simplify how Inputs/Outputs and resource data types are represented.
## 0.16.14 (Released January 31st, 2019)

View file

@ -264,11 +264,16 @@ function createSimpleOutput(val: any) {
* In this example, taking a dependency on d3 means a resource will depend on all the resources of
* d1 and d2.
*/
// This overload is effectively the same as the next. However, it handles `tuples` properly, instead
// of treating them as arrays. Specifically, if you had `[Output<number>, Output<string>]` it would
// give you `Output<[number, string]>` instead of `Output<(number | string)[]>`.
export function all<T extends unknown[]>(xs: T | []): Output<UnwrappedObject<T>>;
export function all<T extends object>(val: T): Output<UnwrappedObject<T>>;
// tslint:disable:max-line-length
export function all<T>(val: Record<string, Input<T>>): Output<Record<string, Unwrap<T>>>;
export function all<T1, T2, T3, T4, T5, T6, T7, T8>(values: [Input<T1> | undefined, Input<T2> | undefined, Input<T3> | undefined, Input<T4> | undefined, Input<T5> | undefined, Input<T6> | undefined, Input<T7> | undefined, Input<T8> | undefined]): Output<[Unwrap<T1>, Unwrap<T2>, Unwrap<T3>, Unwrap<T4>, Unwrap<T5>, Unwrap<T6>, Unwrap<T7>, Unwrap<T8>]>;
export function all<T1, T2, T3, T4, T5, T6, T7>(values: [Input<T1> | undefined, Input<T2> | undefined, Input<T3> | undefined, Input<T4> | undefined, Input<T5> | undefined, Input<T6> | undefined, Input<T7> | undefined]): Output<[Unwrap<T1>, Unwrap<T2>, Unwrap<T3>, Unwrap<T4>, Unwrap<T5>, Unwrap<T6>, Unwrap<T7>]>;
export function all<T1, T2, T3, T4, T5, T6>(values: [Input<T1> | undefined, Input<T2> | undefined, Input<T3> | undefined, Input<T4> | undefined, Input<T5> | undefined, Input<T6> | undefined]): Output<[Unwrap<T1>, Unwrap<T2>, Unwrap<T3>, Unwrap<T4>, Unwrap<T5>, Unwrap<T6>]>;
export function all<T1, T2, T3, T4, T5>(values: [Input<T1> | undefined, Input<T2> | undefined, Input<T3> | undefined, Input<T4> | undefined, Input<T5> | undefined]): Output<[Unwrap<T1>, Unwrap<T2>, Unwrap<T3>, Unwrap<T4>, Unwrap<T5>]>;
export function all<T1, T2, T3, T4>(values: [Input<T1> | undefined, Input<T2> | undefined, Input<T3> | undefined, Input<T4> | undefined]): Output<[Unwrap<T1>, Unwrap<T2>, Unwrap<T3>, Unwrap<T4>]>;
export function all<T1, T2, T3>(values: [Input<T1> | undefined, Input<T2> | undefined, Input<T3> | undefined]): Output<[Unwrap<T1>, Unwrap<T2>, Unwrap<T3>]>;
export function all<T1, T2>(values: [Input<T1> | undefined, Input<T2> | undefined]): Output<[Unwrap<T1>, Unwrap<T2>]>;
export function all<T>(ds: (Input<T> | undefined)[]): Output<Unwrap<T>[]>;
export function all<T>(val: Input<T>[] | Record<string, Input<T>>): Output<any> {
if (val instanceof Array) {
const allOutputs = val.map(v => output(v));
@ -319,6 +324,61 @@ export type Input<T> = T | Promise<T> | Output<T>;
*/
export type Inputs = Record<string, Input<any>>;
/**
* The 'Wrap' type allows us to express the operation of taking a simple POJO type and augmenting it
* so that any values at any levels can be given as Promises or Outputs instead. Note that this
* wrapping is 'deep'. So, if you had:
*
* `type X = { A: { B: { C: boolean } } }`
*
* Then `Wrap<X>` would be equivalent to:
*
* `... = Input<{ A: Input<{ B: Input<{ C: Input<boolean> }> }> }>`
*
* This would then allow someone to pass in values where any of the top level object, or the 'A',
* 'B', or 'C' properties could be any mix of normal JavaScript values, [Promise]s, or [Output]s.
*
* The primary purpose of this type is to serve as the input type to a [Resource]. [Resource]s
* should define a simple POJO type defining what they accept, and then take in a
* `WrappedObject<ThatType>` as their arg. i.e.:
*
* ```ts
* interface CertificateArgs {
* readonly certificateBody: string;
* readonly certificateChain: string;
* }
*
* class Certificate extends pulumi.CustomResource {
* // ...
* constructor(name: string, args?: pulumi.WrappedObject<CertificateArgs>, opts?: pulumi.CustomResourceOptions);
* }
* ```
*
* This allows for a simple way to define the data that is needed, while giving maximum flexibility
* to the caller to pass in acceptable values.
*/
export type Wrap<T> =
// These first four values are to prevent TS from distributing Wrap over a union type
// if we can avoid it. i.e. if we have `T = string | number` then we want to get
// `Input<string | number>` not, `Input<string> | Input<number>`. The last four values
// are to catch things (even for union types if the first four don't match). i.e.
// if we have `T = string | Resource` then we get `Input<string> | Resource` not `never`.
[T] extends [Resource] ? T :
[T] extends [primitive] ? Input<T> :
[T] extends [Array<infer U1>] ? Input<WrappedArray<U1>> :
[T] extends [object] ? Input<WrappedObject<T>> :
T extends Resource ? T :
T extends primitive ? Input<T> :
T extends Array<infer U2> ? Input<WrappedArray<U2>> :
T extends object ? Input<WrappedObject<T>> :
never;
export interface WrappedArray<T> extends Array<Wrap<T>> { }
export type WrappedObject<T> = {
[P in keyof T]: Wrap<Exclude<T[P], undefined>>;
};
/**
* The 'Unwrap' type allows us to express the operation of taking a type, with potentially deeply
* nested Promises and Outputs and to then get that same type with all the Promises and Outputs