-
Notifications
You must be signed in to change notification settings - Fork 196
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
feat(sdk): add Map.tryGet()
, Map.get()
throws on key not found
#3771
feat(sdk): add Map.tryGet()
, Map.get()
throws on key not found
#3771
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔥🚀 awesome job! I added 2 comments feel free to re-request review after you get a chance to review.
…ng#3743) Fixes winglang#3640 This change affects a lot of files, so I've implemented the changes and updated examples in the first commit, and all snapshot updates in the second commit. ## 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)*.
Co-authored-by: Mark McCulloh <[email protected]>
It seems like hangar tests are failing with the error |
@giovanni-orciuolo I think its because the macro's function is not wrapped in braces |
I was wondering why the return was always explicit. Ok! I will commit with braces |
…named (winglang#3739) - Set non-user-defined Function resources as children of the related resource. - Use inflight names for Function resources generated by the compiler. - Enhance the ELK configuration. - Fix the issue where the icon for test resources was not being displayed. - Enable test selection between test explorer and map view. **Current** ![image](https://github.com/winglang/wing/assets/5547636/e670fb5e-c384-4d86-866a-708c19ce73d6) **New** ![image](https://github.com/winglang/wing/assets/5547636/7ae9f22d-b342-452b-b3c6-b3d441bf43d1) *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)*.
In winglang#3743 I introduced some code to avoid name collisions in our code generation by hashing file paths. It seems this was adequate for many cases, but it caused problems for contribution since our `hangar` E2E tests currently compile most Wing programs using absolute paths. That means in these scenarios the hashes will be machine dependent. According to @MarkMcCulloh these tests are needed since there were bugs with absolute paths in the past. To that end, this PR changes the name deduplication strategy to be based around incrementing numbers. ## Checklist - [ ] Title matches [Winglang's style guide](https://www.winglang.io/contributing/start-here/pull_requests#how-are-pull-request-titles-formatted) - [ ] 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)*.
…f-aws` target (winglang#3778) Closes winglang#3764 *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)*.
…#3776) This PR changes the _bind methods, making them public and removing the internal tag. It makes more sense to make this method public, as a Wing class can rewrite the method when necessary. Closes winglang#3775 ## 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) - [x] 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)*.
Following @eladb's recommendation in PR winglang#3398, I removed the import of `target-awscdk` and `target-tf-aws`, and checked if the `host` implements the methods of the `IAwsFunction` interface. This way, the error that was occurring due to not having `aws-cdk-lib` globally installed no longer happens. ## 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)*.
## 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) - [x] Docs updated (only required for features) - [x] 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)*.
Removes the `initialMessages` property from `cloud.Queue` to reduce API surface area in the standard library. This capability has only worked on the `sim` target to date, and it's possible to easily achieve the capability (across clouds) using `cloud.OnDeploy`: ```js bring cloud; let queue = new cloud.Queue(); new cloud.OnDeploy(inflight () => { queue.push("hello"); queue.push("world"); }); ``` This style of API would have more merit if it's something we could provided an optimized implementation for, but it doesn't appear there are dedicated Terraform resources available that represent AWS SQS messages or Google PubSub items. `OnDeploy` also offers more flexibility since it allows the user to dynamically calculate the queue's initial messages based on the results of other inflight operations. Closes winglang#281. BREAKING CHANGE: The field `initialMessages` of `cloud.Queue` has been removed. Instead, use the `cloud.OnDeploy` resource to perform any deploy-time initialization logic. ## 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) - [x] 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)*.
The changes in this PR make it possible to call `fromJson` on any compatible struct definition. ## Implementation notes: Previously we treated the jsification of structs as a no-op since there is not a JS equivalent. So with this change structs now JSify into a `Struct` file that contains a class with a static `jsonSchema` and a `fromJson` function which will allow for field validation at runtime. The schema generated adheres to: https://json-schema.org/understanding-json-schema/ take this simple example Wing code: ```js struct MyStruct { myField: str; myOtherField: num; } ``` this will now generate a JS file named `MyStruct.Struct.js` which looks like this: ```js module.exports = function(stdStruct, fromInline) { class MyStruct { static jsonSchema() { return { id: "/MyStruct", type: "object", properties: { myField: { type: "string" }, myOtherField: { type: "number" }, }, required: [ "myField", "myOtherField", ], $defs: { } } } static fromJson(obj) { return stdStruct._validate(obj, this.jsonSchema()) } static _toInflightType(context) { return fromInline(`require("./MyStruct.Struct.js")(${ context._lift(stdStruct) })`); } } return MyStruct; }; ``` The piece that brings this all together is the addition of the `Struct` class in our std that only has a `fromJson()` methods at the moment that is a Wing macro. The macro just calls the `fromJson()` method in the generated javascript. ### Misc We want to stop the user at compile time from calling `fromJson` on a struct that cannot be represented by a Json value ie ```js struct MyStruct { b: cloud.Bucket; } let j = {}; MyStruct.fromJson(j); ``` to prevent this I added a check in the typechecker for structs to confirm that if `fromJson` is called that all the fields in the struct are valid for conversion attempt See image below for error when attempting: <img width="664" alt="image" src="https://github.com/winglang/wing/assets/45375125/785a2fa6-8823-4fa2-aaa5-4bc8f7ed597f"> Closes: winglang#3653 Closes: winglang#3139 ## TODO: - [x] separate the work done here and the remaining work into different tickets. - [x] update language reference ## Followup issues that are out of scope for this PR: - winglang#3792 - winglang#3790 - winglang#3789 - winglang#3788 ## 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) - [x] Docs updated (only required for features) - [x] 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)*.
Fixes: winglang#3024 winglang#3539 winglang#3342 The problem with the token was the way cdktf is tokenizing strings, I assume it tried to create a new token every time we call `api.url`, or maybe tokenize a token. Now they're all the same- no matter if you call it on preflight or inflight it or assign it to another variable- it'll generate exactly the same token number. other than that: - brought back the aws api SDK tests - changed sim response to be an empty string (in express it's an empty object by default) ## 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)*.
This is a tiny fix removing dead capturing code. For some reason there's code that tries to capture the parent class of a inflight class in the irrelevant case that we're inside an inflight context. In this case the code is dead because an inflight class within an inflight class generates inlined code. The PR also adds some coloring improvements to the env printing I used to debug this and fixed a comment related to parent class capturing. ## 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)*.
From the few runs I looked into, it seems like the reason for failure is either a network error installing wing (is it blocked by NPM in any way?) or occasional fails in the tests themselves... I added a retry option to make them more stable: https://github.com/winglang/wing/actions/runs/5818534372 ## 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)*.
## Checklist - [ ] Title matches [Winglang's style guide](https://www.winglang.io/contributing/start-here/pull_requests#how-are-pull-request-titles-formatted) - [ ] 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)*.
doc updated in wrong area Reverts winglang#3633
Fixing the source_hash in the sdk snapshots to be a string and not a path ## 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)*.
Fixes winglang#3492 * Happened because of un-handled SIGINT termination * Prevented the simulator from being started twice (perhaps more work is needed- for stopping compilation from happening twice) * Changed the error to a warning while cleaning resources- to be able to clean later resources if one fails Here is the result: https://www.loom.com/share/56bddc36c7724d3589a23aebf1141f7a ## 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)*.
…4304) Noticed that today (took less time to fix than to open an issue) Tested on awscdk: <img width="763" alt="image" src="https://github.com/winglang/wing/assets/39455181/75389558-2860-4e39-8f99-d436b7fe47c0"> and tf-aws: <img width="709" alt="image" src="https://github.com/winglang/wing/assets/39455181/0c301b4c-0232-499c-896f-b36ebadab496"> Haven't tested on azure (will be done after that task: winglang#3914 ) Please allow merge only after winglang#4245 ## Checklist - [x] Title matches [Winglang's style guide](https://www.winglang.io/contributing/start-here/pull_requests#how-are-pull-request-titles-formatted) - [ ] 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)*.
Closes winglang#3327 *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)*.
…ang#4349) Adding another field to issue templates, to indicate whether this issue is ready to start implementation or whether some further discussion is needed first. ## Checklist - [ ] Title matches [Winglang's style guide](https://www.winglang.io/contributing/start-here/pull_requests#how-are-pull-request-titles-formatted) - [ ] 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)*.
) ## Checklist tests are passing now tf-aws: <img width="682" alt="image" src="https://github.com/winglang/wing/assets/39455181/082a8633-3a98-450a-a3d5-6d437689132e"> awscdk: <img width="665" alt="image" src="https://github.com/winglang/wing/assets/39455181/f85314db-b7db-4150-96ba-581dfb66b364"> (also fixes: winglang#1526) - [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)*.
fixes [winglang#4139](winglang#4139) https://www.loom.com/share/5b33e2635ed04be2a8502d7fc5f1116f ## 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)*.
*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 PR has not seen activity in 20 days. Therefore, we are marking the PR as stale for now. It will be closed after 7 days. |
…nglang#4329) Closes winglang#3332 *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)*.
This is the first time I am writing tests, so admittedly my tests are not that versatile. But as I also believe that std tests should be straightforward, I do not totally mind it. Since `keys()` and `values()` methods of maps seems to return an array that fails to assert "is the same as another array of same elements" (which seems to be a [bug](winglang#4118)), I had to iterate over the array values and confirm it works as expected. closes: winglang#4363 ## Checklist - [ ] Title matches [Winglang's style guide](https://www.winglang.io/contributing/start-here/pull_requests#how-are-pull-request-titles-formatted) - [ ] 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)*.
Hey @giovanni-orciuolo, thanks for fixing that test. Looks like your branch has some merge conflicts that prevent it from merging to |
- Inform the reader to install within wsl on windows - Add some guides for wsl specific issues - Remove an unused link - Update wording for the codespace badge ## 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) - [x] Docs updated (only required for features) - [x] 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)*.
I was quite behind with commits so I think I did a mess with the merge operation, sorry! I have a bit of free time from work so that's why I can work on this PR, sorry for the prolonged absence. |
Thanks @giovanni-orciuolo! Yeah - I added the |
I wanna give it a fresh review before we merge to main, please
Signed-off-by: monada-bot[bot] <[email protected]>
Signed-off-by: monada-bot[bot] <[email protected]>
Includes the changes from: #3771 that giovanni did. Closes: #3575 ## 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) - [x] Docs updated (only required for features) - [x] 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)*. Co-authored-by: Giovanni Orciuolo <[email protected]> BREAKING CHANGE: `Map.get()` now throws if key does not exist.
Closing this PR now that the changes were migrated to #4523 |
This PR is directly related to this issue: #3575
I modified
Map.get()
to throw an error if the key is not found, and I addedMap.tryGet()
which returnsnil
if the key is not found. I also updated documentation accordingly.Please note that this new behaviour will break current implementations that are relying on the forced typing of
T?
as return value forMap.get()
(since now it throws on key not found no matter the return type). All these implementations should switch toMap.tryGet()
. In alternative, we can inverse the behaviour and make it so thattryGet()
throws andMap.get()
returnsT?
.Checklist
pr/e2e-full
label if this feature requires end-to-end testingBy submitting this pull request, I confirm that my contribution is made under the terms of the Wing Cloud Contribution License.