Skip to content

Commit

Permalink
Merge branch 'main' into mark-upup
Browse files Browse the repository at this point in the history
  • Loading branch information
monadabot authored Sep 4, 2023
2 parents d0c9989 + 6dbb1ac commit 96839af
Show file tree
Hide file tree
Showing 41 changed files with 2,810 additions and 200 deletions.
2 changes: 1 addition & 1 deletion docs/contributing/01-start-here/01-contributing-to-wing.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ to know to help out with the Wing project.
There are many ways to contribute to Wing:

* Reporting bugs through a [GitHub issue](https://github.com/winglang/wing/issues)
* Writing [documentation and guides](https://github.com/winglang/wing/issues?q=is:issue+is:open+sort:updated-desc+label:documentation) or adding [examples](/contributing/start-here/docs#%EF%B8%8F-how-do-i-add-an-example)
* Writing [documentation and guides](https://github.com/winglang/wing/issues?q=is%3Aissue+is%3Aopen+label%3A%22%F0%9F%93%9A+documentation%22) or adding [examples](/contributing/start-here/docs#%EF%B8%8F-how-do-i-add-an-example)
* Setting up your [development environment](/contributing/start-here/development) and working on the code
* Submitting [pull requests](/contributing/start-here/pull_requests) for new features or helping with [reviews](https://github.com/winglang/wing/pulls)
* Picking up a [good first issue](https://github.com/winglang/wing/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22+no%3Aassignee+sort%3Aupdated-desc+) to work on
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/02-concepts/03-compile-targets.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ These targets contain a combination of provisioning engine and cloud environment

## Portability

The [Wing Cloud Library](/docs/category/cloud-resources) has several classes representing abstracted cloud resources, whose APIs are not specific to a single cloud provider.
The [Wing Cloud Library](/docs/category/cloud-library) has several classes representing abstracted cloud resources, whose APIs are not specific to a single cloud provider.
This allows you to write code that can be deployed to any supported cloud environment or provisioning engine.

Here's an example of a portable code snippet:
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/02-concepts/04-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ test "bucket starts empty" {

In the first test (`bucket list should include created file`), a file is created in the bucket. The second test (`bucket starts empty`) verifies that the bucket is initialized without any file.

### Running tests in a the cloud
### Running tests in the cloud

Consider the following example:

Expand Down
12 changes: 6 additions & 6 deletions docs/docs/04-standard-library/02-std/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ Immutable Json.
| <code><a href="#@winglang/sdk.std.Json.asBool">asBool</a></code> | Convert Json element to boolean if possible. |
| <code><a href="#@winglang/sdk.std.Json.asNum">asNum</a></code> | Convert Json element to number if possible. |
| <code><a href="#@winglang/sdk.std.Json.asStr">asStr</a></code> | Convert Json element to string if possible. |
| <code><a href="#@winglang/sdk.std.Json.get">get</a></code> | Returns a specified element from the Json. |
| <code><a href="#@winglang/sdk.std.Json.get">get</a></code> | Returns the value associated with the specified Json key. |
| <code><a href="#@winglang/sdk.std.Json.getAt">getAt</a></code> | Returns a specified element at a given index from Json Array. |
| <code><a href="#@winglang/sdk.std.Json.tryAsBool">tryAsBool</a></code> | Convert Json element to boolean if possible. |
| <code><a href="#@winglang/sdk.std.Json.tryAsNum">tryAsNum</a></code> | Convert Json element to number if possible. |
Expand Down Expand Up @@ -727,13 +727,13 @@ Convert Json element to string if possible.
get(key: str): Json
```

Returns a specified element from the Json.
Returns the value associated with the specified Json key.

###### `key`<sup>Required</sup> <a name="key" id="@winglang/sdk.std.Json.get.parameter.key"></a>

- *Type:* str

The key of the element to return.
The key of the Json property.

---

Expand Down Expand Up @@ -1348,7 +1348,7 @@ Mutable Json.
| <code><a href="#@winglang/sdk.std.MutJson.asBool">asBool</a></code> | Convert Json element to boolean if possible. |
| <code><a href="#@winglang/sdk.std.MutJson.asNum">asNum</a></code> | Convert Json element to number if possible. |
| <code><a href="#@winglang/sdk.std.MutJson.asStr">asStr</a></code> | Convert Json element to string if possible. |
| <code><a href="#@winglang/sdk.std.MutJson.get">get</a></code> | Returns a specified element from the Json. |
| <code><a href="#@winglang/sdk.std.MutJson.get">get</a></code> | Returns the value associated with the specified Json key. |
| <code><a href="#@winglang/sdk.std.MutJson.getAt">getAt</a></code> | Returns a specified element at a given index from MutJson Array. |
| <code><a href="#@winglang/sdk.std.MutJson.set">set</a></code> | Adds or updates an element in MutJson with a specific key and value. |
| <code><a href="#@winglang/sdk.std.MutJson.setAt">setAt</a></code> | Set element in MutJson Array with a specific key and value. |
Expand Down Expand Up @@ -1390,13 +1390,13 @@ Convert Json element to string if possible.
get(key: str): MutJson
```

Returns a specified element from the Json.
Returns the value associated with the specified Json key.

###### `key`<sup>Required</sup> <a name="key" id="@winglang/sdk.std.MutJson.get.parameter.key"></a>

- *Type:* str

The key of the element to return.
The key of the Json property.

---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ You can also check out our [roadmap](https://www.winglang.io/contributing/status
If there are other services you would like to see supported, please let us know through our GitHub or Slack!

## You can use any Terraform resource
Beyond the built-in set of resources in the [Wing Cloud Library](../../standard-library/cloud), you can use any Terraform resource by importing a [CDKTF](https://github.com/hashicorp/terraform-cdk) library corresponding to any given Terraform provider.
Beyond the built-in set of resources in the [Wing Cloud Library](../../category/cloud-library), you can use any Terraform resource by importing a [CDKTF](https://github.com/hashicorp/terraform-cdk) library corresponding to any given Terraform provider.

64 changes: 64 additions & 0 deletions examples/tests/sdk_tests/api/path_vars.w
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
bring cloud;
bring http;

let api = new cloud.Api();


let handler = inflight (req: cloud.ApiRequest): cloud.ApiResponse => {
return cloud.ApiResponse {
body: Json.stringify({ user: req.vars.get("name") }),
headers: { "content-type" => "application/json" },
status: 200
};
};

let handler_two = inflight (req: cloud.ApiRequest): cloud.ApiResponse => {
return cloud.ApiResponse {
body: Json.stringify({ user: req.vars.get("name"), age: req.vars.get("age") }),
headers: { "content-type" => "application/json" },
status: 200
};
};

api.get("/users/{name}", handler);
api.get("/path/{name}", handler);
api.get("/users/permission/{name}", handler);
api.get("/path/{name}/{age}", handler_two);

test "test" {
let username = "tsuf";
let res: http.Response = http.get("${api.url}/users/${username}");


assert(res.status == 200);
assert(Json.parse(res.body ?? "").get("user") == username);
}

test "test2" {
let username = "akhil";
let res: http.Response = http.get("${api.url}/path/${username}");


assert(res.status == 200);
assert(Json.parse(res.body ?? "").get("user") == username);
}

test "test3" {
let username = "akhil";
let res: http.Response = http.get("${api.url}/users/permission/${username}");


assert(res.status == 200);
assert(Json.parse(res.body ?? "").get("user") == username);
}

test "test4" {
let username = "akhil";
let age = "23";
let res: http.Response = http.get("${api.url}/path/${username}/${age}");


assert(res.status == 200);
assert(Json.parse(res.body ?? "").get("user") == username);
assert(Json.parse(res.body ?? "").get("age") == age);
}
111 changes: 75 additions & 36 deletions examples/tests/sdk_tests/std/json.w
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,86 @@
//-----------------------------------------------------------------------------
bring cloud;

// set() & get()
let a = MutJson { a: 1 };
let b = MutJson { b: 2 };
a.set("c", b);
test "get()" {
let assertThrows = (expected: str, block: (): void) => {
let var error = false;
try {
block();
} catch actual {
assert(actual == expected);
error = true;
}
assert(error);
};

let c = a.get("c");
assert(c.get("b") == 2);
let JSON_PROPERTY_DOES_NOT_EXIST_ERROR = "Json property \"c\" does not exist";
let obj = Json { a: 1, b: 2 };
let mutObj = MutJson { a: 1, b: 2 };

test "set()" {
let x = MutJson { a: 1 };
x.set("b", 2);
let y = x.get("b");
assert(y == 2);
assert(obj.get("b") == 2);
assert(mutObj.get("b") == 2);

assertThrows(JSON_PROPERTY_DOES_NOT_EXIST_ERROR, () => {
obj.get("c");
});
assertThrows(JSON_PROPERTY_DOES_NOT_EXIST_ERROR, () => {
mutObj.get("c");
});
}

//-----------------------------------------------------------------------------
// setAt() & getAt()
let d = MutJson { d: 3 };
a.setAt(2, d);
let e = a.getAt(2);
assert(e.get("d") == 3);
test "getAt()" {
let assertThrows = (expected: str, block: (): void) => {
let var error = false;
try {
block();
} catch actual {
assert(actual == expected);
error = true;
}
assert(error);
};

let INDEX_OUT_OF_BOUNDS_ERROR = "Index out of bounds";
let jsonArray = Json ["foo", "bar", "baz"];
let mutJsonArray = MutJson [1, 2, 3];

assert(jsonArray.getAt(2) == "baz");
assert(mutJsonArray.getAt(2) == 3);

assertThrows(INDEX_OUT_OF_BOUNDS_ERROR, () => {
jsonArray.getAt(3);
mutJsonArray.getAt(3);
});
}

test "set()" {
let mutObj = MutJson { x: 1, y: 2 };

mutObj.set("x", -1);
mutObj.set("z", 3);

assert(mutObj.get("x") == -1);
assert(mutObj.get("z") == 3);
}

test "setAt()" {
let x = MutJson { a: 1 };
let a = MutJson { c: 3 };
x.setAt(2, a);
let d = x.getAt(2);
assert(d.get("c") == 3);
let mutJsonArray = MutJson [1, 2, 3];

mutJsonArray.setAt(0, -1);
mutJsonArray.setAt(3, 3);

assert(mutJsonArray.getAt(0) == -1);
assert(mutJsonArray.getAt(3) == 3);
}

test "stringify()" {
let obj = Json { a: 1, b: 2 };

let stringified = Json.stringify(obj);
let stringifiedIndent = Json.stringify(obj, indent: 2);

assert(stringified == "{\"a\":1,\"b\":2}");
assert(stringifiedIndent == "{\n \"a\": 1,\n \"b\": 2\n}");
}

//-----------------------------------------------------------------------------
Expand All @@ -53,17 +105,4 @@ try {
log(error);
assert(error == "");
}
*/

//-----------------------------------------------------------------------------
// stringify()

test "stringify()" {
let obj = Json { a: 1, b: 2 };

let stringified = Json.stringify(obj);
let stringifiedIndent = Json.stringify(obj, indent: 2);

assert(stringified == "{\"a\":1,\"b\":2}");
assert(stringifiedIndent == "{\n \"a\": 1,\n \"b\": 2\n}");
}
*/
25 changes: 0 additions & 25 deletions examples/tests/valid/api_path_vars.w

This file was deleted.

18 changes: 17 additions & 1 deletion examples/tests/valid/api_valid_path.w
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,27 @@ testInvalidPath("/test/path/{unclosed");
testInvalidPath("/test/m{issplaced}");
testInvalidPath("/test/{misspla}ced");
testInvalidPath("/test/{}/empty");

testInvalidPath("/{sup:er/:annoying//path}");
testInvalidPath("/{::another:annoying:path}");
testInvalidPath("/n0t_alphanumer1cPa:th");
testInvalidPath("/{with}/{two:invali4d#}/variables");
testInvalidPath("/{unclosed");
testInvalidPath("/m{issplaced}");
testInvalidPath("/{misspla}ced");
testInvalidPath("test");
testInvalidPath("/{}/empty");
testInvalidPath("/{}");


// valid paths
testValidPath("/test");
testValidPath("/test/alphanumer1cPa_th");
testValidPath("/test/regular/path");
testValidPath("/test/pa-th/{with}/two/{variable_s}/f?bla=5&b=6");
testValidPath("/test/param/is/{last}");
testValidPath("/test/{param}");
testValidPath("/{param}");
testValidPath("/t/{param}");
testValidPath("/test/regular/path/{param}");
testValidPath("/test/segment1/{param1}/segment2?query1=value1?query2=value2");
testValidPath("/test/segment1/segment2?query=value1&query2=value2");
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ source: libs/wingc/src/lsp/completions.rs
detail: "(key: str): MutJson"
documentation:
kind: markdown
value: "```wing\nget: (key: str): MutJson\n```\n---\nReturns a specified element from the Json.\n\n\n### Returns\nThe element associated with the specified key, or undefined if the key can't be found"
value: "```wing\nget: (key: str): MutJson\n```\n---\nReturns the value associated with the specified Json key.\n\n\n### Returns\nThe value associated with the specified Json key\n\n*@throws* *Json property does not exist if the given key is not part of an existing property*"
sortText: ff|get
insertText: get($0)
insertTextFormat: 2
Expand All @@ -42,7 +42,7 @@ source: libs/wingc/src/lsp/completions.rs
detail: "(index: num): MutJson"
documentation:
kind: markdown
value: "```wing\ngetAt: (index: num): MutJson\n```\n---\nReturns a specified element at a given index from MutJson Array.\n\n\n### Returns\nThe element at given index in MutJson Array, or undefined if index is not valid"
value: "```wing\ngetAt: (index: num): MutJson\n```\n---\nReturns a specified element at a given index from MutJson Array.\n\n\n### Returns\nThe element at given index in MutJson Array\n\n*@throws* *index out of bounds error if the given index does not exist for the MutJson Array*"
sortText: ff|getAt
insertText: getAt($0)
insertTextFormat: 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ source: libs/wingc/src/lsp/completions.rs
detail: "(key: str): Json"
documentation:
kind: markdown
value: "```wing\nget: (key: str): Json\n```\n---\nReturns a specified element from the Json.\n\n\n### Returns\nThe element associated with the specified key, or undefined if the key can't be found"
value: "```wing\nget: (key: str): Json\n```\n---\nReturns the value associated with the specified Json key.\n\n\n### Returns\nThe value associated with the specified Json key\n\n*@throws* *Json property does not exist if the given key is not part of an existing property*"
sortText: ff|get
insertText: get($0)
insertTextFormat: 2
Expand All @@ -42,7 +42,7 @@ source: libs/wingc/src/lsp/completions.rs
detail: "(index: num): Json"
documentation:
kind: markdown
value: "```wing\ngetAt: (index: num): Json\n```\n---\nReturns a specified element at a given index from Json Array.\n\n\n### Returns\nThe element at given index in Json Array, or undefined if index is not valid"
value: "```wing\ngetAt: (index: num): Json\n```\n---\nReturns a specified element at a given index from Json Array.\n\n\n### Returns\nThe element at given index in Json Array\n\n*@throws* *index out of bounds error if the given index does not exist for the Json Array*"
sortText: ff|getAt
insertText: getAt($0)
insertTextFormat: 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ source: libs/wingc/src/lsp/completions.rs
detail: "(key: str): Json"
documentation:
kind: markdown
value: "```wing\nget: (key: str): Json\n```\n---\nReturns a specified element from the Json.\n\n\n### Returns\nThe element associated with the specified key, or undefined if the key can't be found"
value: "```wing\nget: (key: str): Json\n```\n---\nReturns the value associated with the specified Json key.\n\n\n### Returns\nThe value associated with the specified Json key\n\n*@throws* *Json property does not exist if the given key is not part of an existing property*"
sortText: ff|get
insertText: get($0)
insertTextFormat: 2
Expand All @@ -78,7 +78,7 @@ source: libs/wingc/src/lsp/completions.rs
detail: "(index: num): Json"
documentation:
kind: markdown
value: "```wing\ngetAt: (index: num): Json\n```\n---\nReturns a specified element at a given index from Json Array.\n\n\n### Returns\nThe element at given index in Json Array, or undefined if index is not valid"
value: "```wing\ngetAt: (index: num): Json\n```\n---\nReturns a specified element at a given index from Json Array.\n\n\n### Returns\nThe element at given index in Json Array\n\n*@throws* *index out of bounds error if the given index does not exist for the Json Array*"
sortText: ff|getAt
insertText: getAt($0)
insertTextFormat: 2
Expand Down
Loading

0 comments on commit 96839af

Please sign in to comment.