-
Notifications
You must be signed in to change notification settings - Fork 201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot extend non-Wing constructs #3717
Comments
When trying to bring `cdk8s` and extend `Chart`, the call to `this._addInflightOps()` fails because non-wing constructs don't have this method. The fix is to use `?.()` (e.g. `this._addInflightOps?.()`) in order to chain the undefined. Added a test which verifies that cdk8s can be brought and used. Fixes #3717
@eladb I'm curious if using composition is a workaround for your use case? (trying to understand priority of this) |
Background: in order for Wing classes to support extending non-Wing classes (#3717), I'm trying to remove the `Resource` class in the SDK so that all classes generated by our compiler just need to extend the ol' [`construct.Construct`](https://github.com/aws/constructs/tree/10.x) class -- the "base class" of the JSII ecosystem. This is a tricky effort since `Resource` is used in many places, and it collected a lot of responsibilities over the past year. This PR takes a first step towards that by removing the connection-related information from the `Resource` class: https://github.com/winglang/wing/blob/1c9954e50ebdd4f2b290e91665c920fb504c9cb7/libs/wingsdk/src/std/resource.ts#L222-L223 Instead, we now store the information inside the root of the construct tree. It can be accessed through `Connections.of(x)` where `x` is any class instance. See `connections.ts` for the full implementation (its short). With this refactoring, I took the opportunity to clean up how connections are modeled. Previously, we were storing each connection twice inside `tree.json` (once next to the connection's source, and a second time next to the connection's target). Now, we just store each connection once, in a flat array inside `connections.json`. (I wasn't sure if it makes more sense to put it in a separate file - I'm interested in feedback on this). I also removed the `implicit` field which wasn't used by the SDK or console anywhere. ## 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 - [x] 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)*.
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)*.
Hi, This issue hasn't seen activity in 60 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. |
Thanks for the heads up @staycoolcall911. It looks like the immediate bug above was fixed (I think via #4640), but if I extend the example a little further with some inflight code, we still get errors: bring "cdk8s" as cdk8s;
bring cloud;
let global_b = new cloud.Bucket();
class MyChart extends cdk8s.Chart {
local_b: cloud.Bucket;
init() {
new cdk8s.ApiObject(kind: "Pod", apiVersion: "v1");
this.local_b = new cloud.Bucket();
}
pub inflight save() {
global_b.put("data.txt", "Hello World!");
this.local_b.put("data.txt", "Hello World!");
}
}
let c = new MyChart();
new cloud.Function(inflight () => {
c.save();
}); error:
I think the root cause is our lifting system is still assuming |
Hi, This issue hasn't seen activity in 90 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. |
From my testing it looks like the previous example now works. I was able to uncover a separate issue but it's more minor: #6629 Closing. |
I tried this:
This happened:
I expected this:
To work
Is there a workaround?
No response
Component
Compiler, SDK
Wing Version
No response
Node.js Version
No response
Platform(s)
No response
Anything else?
No response
Community Notes
The text was updated successfully, but these errors were encountered: