-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Summary BREAKING CHANGE: `app.platformParameters` has been changed to `app.parameters` This PR now allows Wing authors to access the application's parameters through `app.parameters` for example: ```js let parameters = nodeof(this).app.parameters; ``` This also means that now wing structs can easily be added to platform parameters through the use of `parameters.addSchema(Struct.schema())` as well structs can be read from the parameter list through `Struct.fromJson(parameters.read())` ## 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)*.
- Loading branch information
1 parent
dcd47d9
commit effc7ac
Showing
41 changed files
with
675 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
let app = nodeof(this).app; | ||
|
||
struct MyParams { | ||
foo: str; | ||
} | ||
|
||
app.parameters.addSchema(MyParams.schema()); | ||
|
||
// Error: Parameter validation errors: | ||
// - must have required property 'foo' | ||
|
||
// (hint: make sure to use --values to provide the required parameters file) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
struct MyParams { | ||
foo: str; | ||
bar: bool; | ||
baz: num; | ||
} | ||
|
||
|
||
let app = nodeof(this).app; | ||
|
||
// Never added the schema to the parameters, so | ||
// technically we never enforced the parameters must have been | ||
// provided | ||
|
||
MyParams.fromJson(app.parameters.read()); | ||
//Error: unable to parse MyParams: | ||
// - instance requires property "bar" | ||
// - instance requires property "baz" | ||
// - instance requires property "foo" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
struct Person { | ||
name: str; | ||
age: num; | ||
} | ||
|
||
struct House { | ||
address: str; | ||
residents: Array<Person>; | ||
} | ||
|
||
struct MyParams { | ||
houses: Array<House>; | ||
} | ||
|
||
let app = nodeof(this).app; | ||
|
||
let myParams = MyParams.fromJson(app.parameters.read(schema: MyParams.schema())); | ||
|
||
assert(myParams.houses.length == 2); | ||
assert(myParams.houses.at(0).address == "123 Main St"); | ||
assert(myParams.houses.at(0).residents.length == 2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[[houses]] | ||
address = "123 Main St" | ||
residents = [ | ||
{name = "John Doe", age = 30}, | ||
{name = "Jane Doe", age = 24} | ||
] | ||
|
||
[[houses]] | ||
address = "456 Elm St" | ||
residents = [ | ||
{name = "Tom Smith", age = 45}, | ||
{name = "Sue Smith", age = 40} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
let app = nodeof(this).app; | ||
|
||
struct MyParams { | ||
foo: str?; | ||
meaningOfLife: num; | ||
} | ||
|
||
let myParams = MyParams.fromJson(app.parameters.read(schema: MyParams.schema())); | ||
|
||
if let foo = myParams.foo { | ||
assert(false); // shouldnt happen | ||
} else { | ||
assert(true); | ||
} | ||
|
||
let meaningOfLife = myParams.meaningOfLife; | ||
|
||
assert(meaningOfLife == 42); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
meaningOfLife = 42 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.