Skip to content

Commit

Permalink
feat(sdk)!: std.Node (#3884)
Browse files Browse the repository at this point in the history
As part of the effort to fix #3717, I'm trying to refactor some parts of the SDK so that we do not need to rely on the `std.Resource` class.  The issue this PR addresses is that the `Resource` class has an extra property named `display` which is not available if you extend `cdk8s.Chart`:

```js
bring cdk8s;

class Bar {
  init() {
    this.display.title = "hi"; // OK
  }
}

class MyChart extends cdk8s.Chart {
  init() {
    this.display.title = "hello"; // error: Unknown symbol "display"
  }
}
```

The solution implemented by this PR is to standardize display property access through `std.Node`:

```js
bring cdk8s;

class Bar {
  init() {
    std.Node.of(this).title = "hi"; // OK
  }
}

// once #3717 is fixed
class MyChart extends cdk8s.Chart {
  init() {
    std.Node.of(this).title = "hello"; // OK
  }
}
```

`std.Node.of(this)` also allows you toaccess all other fields and methods normally available through the `constructs.Node` class.

Other changes:
- I've replaced the `_addInflightOps` method from `std.Resource` with an API contract where a class can (optionally) implement a method named `_getInflightOps()`. This removes one more of the places where the compiler assumes behavior that only exists on `std.Resource` and not on `constructs.Construct`. 
- I've removed the `Code` class from the SDK. I looked through our codebase and 100% of the usages have just been to access its `text` field, so the class isn't really doing anything important. Just using plain `string`'s seems like a nice simplification.

BREAKING CHANGE: `.display` property is no longer available in Wing classes. To change how classes are displayed in the Wing Console, use `std.Node.of(this)` and modify fields like `.title` and `.description`.

## Checklist

- [x] Title matches [Winglang's style guide](https://www.winglang.io/contributing/start-here/pull_requests#how-are-pull-request-titles-formatted)
- [x] Description explains motivation and solution
- [ ] Tests added (always)
- [ ] Docs updated (only required for features)
- [ ] Added `pr/e2e-full` label if this feature requires end-to-end testing

*By submitting this pull request, I confirm that my contribution is made under the terms of the [Wing Cloud Contribution License](https://github.com/winglang/wing/blob/main/CONTRIBUTION_LICENSE.md)*.
  • Loading branch information
Chriscbr authored Aug 24, 2023
1 parent 1184705 commit 8efecc2
Show file tree
Hide file tree
Showing 415 changed files with 7,066 additions and 5,490 deletions.
26 changes: 0 additions & 26 deletions docs/docs/04-standard-library/01-cloud/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,6 @@ Options for the route.
| **Name** | **Type** | **Description** |
| --- | --- | --- |
| <code><a href="#@winglang/sdk.cloud.Api.property.node">node</a></code> | <code>constructs.Node</code> | The tree node. |
| <code><a href="#@winglang/sdk.cloud.Api.property.display">display</a></code> | <code><a href="#@winglang/sdk.std.Display">Display</a></code> | Information on how to display a resource in the UI. |
| <code><a href="#@winglang/sdk.cloud.Api.property.url">url</a></code> | <code>str</code> | The base URL of the API endpoint. |
---
Expand All @@ -439,18 +438,6 @@ The tree node.
---
##### `display`<sup>Required</sup> <a name="display" id="@winglang/sdk.cloud.Api.property.display"></a>
```wing
display: Display;
```
- *Type:* <a href="#@winglang/sdk.std.Display">Display</a>
Information on how to display a resource in the UI.
---
##### `url`<sup>Required</sup> <a name="url" id="@winglang/sdk.cloud.Api.property.url"></a>
```wing
Expand Down Expand Up @@ -757,7 +744,6 @@ A resource with an inflight "handle" method that can be passed to one of the `Ap
| **Name** | **Type** | **Description** |
| --- | --- | --- |
| <code><a href="#@winglang/sdk.cloud.IApiEndpointHandler.property.node">node</a></code> | <code>constructs.Node</code> | The tree node. |
| <code><a href="#@winglang/sdk.cloud.IApiEndpointHandler.property.display">display</a></code> | <code><a href="#@winglang/sdk.std.Display">Display</a></code> | Information on how to display a resource in the UI. |
---
Expand All @@ -773,18 +759,6 @@ The tree node.
---
##### `display`<sup>Required</sup> <a name="display" id="@winglang/sdk.cloud.IApiEndpointHandler.property.display"></a>
```wing
display: Display;
```
- *Type:* <a href="#@winglang/sdk.std.Display">Display</a>
Information on how to display a resource in the UI.
---
### IApiEndpointHandlerClient <a name="IApiEndpointHandlerClient" id="@winglang/sdk.cloud.IApiEndpointHandlerClient"></a>
- *Implemented By:* <a href="#@winglang/sdk.cloud.IApiEndpointHandlerClient">IApiEndpointHandlerClient</a>
Expand Down
26 changes: 0 additions & 26 deletions docs/docs/04-standard-library/01-cloud/bucket.md
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,6 @@ Key of the object.
| **Name** | **Type** | **Description** |
| --- | --- | --- |
| <code><a href="#@winglang/sdk.cloud.Bucket.property.node">node</a></code> | <code>constructs.Node</code> | The tree node. |
| <code><a href="#@winglang/sdk.cloud.Bucket.property.display">display</a></code> | <code><a href="#@winglang/sdk.std.Display">Display</a></code> | Information on how to display a resource in the UI. |

---

Expand All @@ -532,18 +531,6 @@ The tree node.

---

##### `display`<sup>Required</sup> <a name="display" id="@winglang/sdk.cloud.Bucket.property.display"></a>

```wing
display: Display;
```

- *Type:* <a href="#@winglang/sdk.std.Display">Display</a>

Information on how to display a resource in the UI.

---



## Structs <a name="Structs" id="Structs"></a>
Expand Down Expand Up @@ -729,7 +716,6 @@ A resource with an inflight "handle" method that can be passed to the bucket eve
| **Name** | **Type** | **Description** |
| --- | --- | --- |
| <code><a href="#@winglang/sdk.cloud.IBucketEventHandler.property.node">node</a></code> | <code>constructs.Node</code> | The tree node. |
| <code><a href="#@winglang/sdk.cloud.IBucketEventHandler.property.display">display</a></code> | <code><a href="#@winglang/sdk.std.Display">Display</a></code> | Information on how to display a resource in the UI. |

---

Expand All @@ -745,18 +731,6 @@ The tree node.

---

##### `display`<sup>Required</sup> <a name="display" id="@winglang/sdk.cloud.IBucketEventHandler.property.display"></a>

```wing
display: Display;
```

- *Type:* <a href="#@winglang/sdk.std.Display">Display</a>

Information on how to display a resource in the UI.

---

### IBucketEventHandlerClient <a name="IBucketEventHandlerClient" id="@winglang/sdk.cloud.IBucketEventHandlerClient"></a>

- *Implemented By:* <a href="#@winglang/sdk.cloud.IBucketEventHandlerClient">IBucketEventHandlerClient</a>
Expand Down
13 changes: 0 additions & 13 deletions docs/docs/04-standard-library/01-cloud/counter.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ specify the key to be set.
| **Name** | **Type** | **Description** |
| --- | --- | --- |
| <code><a href="#@winglang/sdk.cloud.Counter.property.node">node</a></code> | <code>constructs.Node</code> | The tree node. |
| <code><a href="#@winglang/sdk.cloud.Counter.property.display">display</a></code> | <code><a href="#@winglang/sdk.std.Display">Display</a></code> | Information on how to display a resource in the UI. |
| <code><a href="#@winglang/sdk.cloud.Counter.property.initial">initial</a></code> | <code>num</code> | The initial value of the counter. |

---
Expand All @@ -225,18 +224,6 @@ The tree node.

---

##### `display`<sup>Required</sup> <a name="display" id="@winglang/sdk.cloud.Counter.property.display"></a>

```wing
display: Display;
```

- *Type:* <a href="#@winglang/sdk.std.Display">Display</a>

Information on how to display a resource in the UI.

---

##### `initial`<sup>Required</sup> <a name="initial" id="@winglang/sdk.cloud.Counter.property.initial"></a>

```wing
Expand Down
26 changes: 0 additions & 26 deletions docs/docs/04-standard-library/01-cloud/function.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ Invoke the function asynchronously with a given payload.
| **Name** | **Type** | **Description** |
| --- | --- | --- |
| <code><a href="#@winglang/sdk.cloud.Function.property.node">node</a></code> | <code>constructs.Node</code> | The tree node. |
| <code><a href="#@winglang/sdk.cloud.Function.property.display">display</a></code> | <code><a href="#@winglang/sdk.std.Display">Display</a></code> | Information on how to display a resource in the UI. |
| <code><a href="#@winglang/sdk.cloud.Function.property.env">env</a></code> | <code>MutMap&lt;str&gt;</code> | Returns the set of environment variables for this function. |

---
Expand All @@ -168,18 +167,6 @@ The tree node.

---

##### `display`<sup>Required</sup> <a name="display" id="@winglang/sdk.cloud.Function.property.display"></a>

```wing
display: Display;
```

- *Type:* <a href="#@winglang/sdk.std.Display">Display</a>

Information on how to display a resource in the UI.

---

##### `env`<sup>Required</sup> <a name="env" id="@winglang/sdk.cloud.Function.property.env"></a>

```wing
Expand Down Expand Up @@ -275,7 +262,6 @@ A resource with an inflight "handle" method that can be used to create a `cloud.
| **Name** | **Type** | **Description** |
| --- | --- | --- |
| <code><a href="#@winglang/sdk.cloud.IFunctionHandler.property.node">node</a></code> | <code>constructs.Node</code> | The tree node. |
| <code><a href="#@winglang/sdk.cloud.IFunctionHandler.property.display">display</a></code> | <code><a href="#@winglang/sdk.std.Display">Display</a></code> | Information on how to display a resource in the UI. |

---

Expand All @@ -291,18 +277,6 @@ The tree node.

---

##### `display`<sup>Required</sup> <a name="display" id="@winglang/sdk.cloud.IFunctionHandler.property.display"></a>

```wing
display: Display;
```

- *Type:* <a href="#@winglang/sdk.std.Display">Display</a>

Information on how to display a resource in the UI.

---

### IFunctionHandlerClient <a name="IFunctionHandlerClient" id="@winglang/sdk.cloud.IFunctionHandlerClient"></a>

- *Implemented By:* <a href="#@winglang/sdk.cloud.IFunctionHandlerClient">IFunctionHandlerClient</a>
Expand Down
26 changes: 0 additions & 26 deletions docs/docs/04-standard-library/01-cloud/on-deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ new cloud.OnDeploy(handler: IOnDeployHandler, props?: OnDeployProps);
| **Name** | **Type** | **Description** |
| --- | --- | --- |
| <code><a href="#@winglang/sdk.cloud.OnDeploy.property.node">node</a></code> | <code>constructs.Node</code> | The tree node. |
| <code><a href="#@winglang/sdk.cloud.OnDeploy.property.display">display</a></code> | <code><a href="#@winglang/sdk.std.Display">Display</a></code> | Information on how to display a resource in the UI. |

---

Expand All @@ -121,18 +120,6 @@ The tree node.

---

##### `display`<sup>Required</sup> <a name="display" id="@winglang/sdk.cloud.OnDeploy.property.display"></a>

```wing
display: Display;
```

- *Type:* <a href="#@winglang/sdk.std.Display">Display</a>

Information on how to display a resource in the UI.

---



## Structs <a name="Structs" id="Structs"></a>
Expand Down Expand Up @@ -244,7 +231,6 @@ A resource with an inflight "handle" method that can be used by `cloud.OnDeploy`
| **Name** | **Type** | **Description** |
| --- | --- | --- |
| <code><a href="#@winglang/sdk.cloud.IOnDeployHandler.property.node">node</a></code> | <code>constructs.Node</code> | The tree node. |
| <code><a href="#@winglang/sdk.cloud.IOnDeployHandler.property.display">display</a></code> | <code><a href="#@winglang/sdk.std.Display">Display</a></code> | Information on how to display a resource in the UI. |

---

Expand All @@ -260,18 +246,6 @@ The tree node.

---

##### `display`<sup>Required</sup> <a name="display" id="@winglang/sdk.cloud.IOnDeployHandler.property.display"></a>

```wing
display: Display;
```

- *Type:* <a href="#@winglang/sdk.std.Display">Display</a>

Information on how to display a resource in the UI.

---

### IOnDeployHandlerClient <a name="IOnDeployHandlerClient" id="@winglang/sdk.cloud.IOnDeployHandlerClient"></a>

- *Implemented By:* <a href="#@winglang/sdk.cloud.IOnDeployHandlerClient">IOnDeployHandlerClient</a>
Expand Down
26 changes: 0 additions & 26 deletions docs/docs/04-standard-library/01-cloud/queue.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ Payload to send to the queue.
| **Name** | **Type** | **Description** |
| --- | --- | --- |
| <code><a href="#@winglang/sdk.cloud.Queue.property.node">node</a></code> | <code>constructs.Node</code> | The tree node. |
| <code><a href="#@winglang/sdk.cloud.Queue.property.display">display</a></code> | <code><a href="#@winglang/sdk.std.Display">Display</a></code> | Information on how to display a resource in the UI. |

---

Expand All @@ -205,18 +204,6 @@ The tree node.

---

##### `display`<sup>Required</sup> <a name="display" id="@winglang/sdk.cloud.Queue.property.display"></a>

```wing
display: Display;
```

- *Type:* <a href="#@winglang/sdk.std.Display">Display</a>

Information on how to display a resource in the UI.

---



## Structs <a name="Structs" id="Structs"></a>
Expand Down Expand Up @@ -361,7 +348,6 @@ A resource with an inflight "handle" method that can be passed to `Queue.setCons
| **Name** | **Type** | **Description** |
| --- | --- | --- |
| <code><a href="#@winglang/sdk.cloud.IQueueSetConsumerHandler.property.node">node</a></code> | <code>constructs.Node</code> | The tree node. |
| <code><a href="#@winglang/sdk.cloud.IQueueSetConsumerHandler.property.display">display</a></code> | <code><a href="#@winglang/sdk.std.Display">Display</a></code> | Information on how to display a resource in the UI. |

---

Expand All @@ -377,18 +363,6 @@ The tree node.

---

##### `display`<sup>Required</sup> <a name="display" id="@winglang/sdk.cloud.IQueueSetConsumerHandler.property.display"></a>

```wing
display: Display;
```

- *Type:* <a href="#@winglang/sdk.std.Display">Display</a>

Information on how to display a resource in the UI.

---

### IQueueSetConsumerHandlerClient <a name="IQueueSetConsumerHandlerClient" id="@winglang/sdk.cloud.IQueueSetConsumerHandlerClient"></a>

- *Implemented By:* <a href="#@winglang/sdk.cloud.IQueueSetConsumerHandlerClient">IQueueSetConsumerHandlerClient</a>
Expand Down
26 changes: 0 additions & 26 deletions docs/docs/04-standard-library/01-cloud/schedule.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ Create a function that runs when receiving the scheduled event.
| **Name** | **Type** | **Description** |
| --- | --- | --- |
| <code><a href="#@winglang/sdk.cloud.Schedule.property.node">node</a></code> | <code>constructs.Node</code> | The tree node. |
| <code><a href="#@winglang/sdk.cloud.Schedule.property.display">display</a></code> | <code><a href="#@winglang/sdk.std.Display">Display</a></code> | Information on how to display a resource in the UI. |

---

Expand All @@ -138,18 +137,6 @@ The tree node.

---

##### `display`<sup>Required</sup> <a name="display" id="@winglang/sdk.cloud.Schedule.property.display"></a>

```wing
display: Display;
```

- *Type:* <a href="#@winglang/sdk.std.Display">Display</a>

Information on how to display a resource in the UI.

---



## Structs <a name="Structs" id="Structs"></a>
Expand Down Expand Up @@ -297,7 +284,6 @@ A resource with an inflight "handle" method that can be passed to `Schedule.on_t
| **Name** | **Type** | **Description** |
| --- | --- | --- |
| <code><a href="#@winglang/sdk.cloud.IScheduleOnTickHandler.property.node">node</a></code> | <code>constructs.Node</code> | The tree node. |
| <code><a href="#@winglang/sdk.cloud.IScheduleOnTickHandler.property.display">display</a></code> | <code><a href="#@winglang/sdk.std.Display">Display</a></code> | Information on how to display a resource in the UI. |

---

Expand All @@ -313,18 +299,6 @@ The tree node.

---

##### `display`<sup>Required</sup> <a name="display" id="@winglang/sdk.cloud.IScheduleOnTickHandler.property.display"></a>

```wing
display: Display;
```

- *Type:* <a href="#@winglang/sdk.std.Display">Display</a>

Information on how to display a resource in the UI.

---

### IScheduleOnTickHandlerClient <a name="IScheduleOnTickHandlerClient" id="@winglang/sdk.cloud.IScheduleOnTickHandlerClient"></a>

- *Implemented By:* <a href="#@winglang/sdk.cloud.IScheduleOnTickHandlerClient">IScheduleOnTickHandlerClient</a>
Expand Down
13 changes: 0 additions & 13 deletions docs/docs/04-standard-library/01-cloud/secret.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ Retrieve the Json value of the secret.
| **Name** | **Type** | **Description** |
| --- | --- | --- |
| <code><a href="#@winglang/sdk.cloud.Secret.property.node">node</a></code> | <code>constructs.Node</code> | The tree node. |
| <code><a href="#@winglang/sdk.cloud.Secret.property.display">display</a></code> | <code><a href="#@winglang/sdk.std.Display">Display</a></code> | Information on how to display a resource in the UI. |

---

Expand All @@ -170,18 +169,6 @@ The tree node.

---

##### `display`<sup>Required</sup> <a name="display" id="@winglang/sdk.cloud.Secret.property.display"></a>

```wing
display: Display;
```

- *Type:* <a href="#@winglang/sdk.std.Display">Display</a>

Information on how to display a resource in the UI.

---



## Structs <a name="Structs" id="Structs"></a>
Expand Down
Loading

0 comments on commit 8efecc2

Please sign in to comment.