Skip to content

Commit

Permalink
chore: use indexing syntax (#204)
Browse files Browse the repository at this point in the history
Cosmetic refactorings to our winglibs to use the new indexing syntax where applicable. This is mostly done as an effort to test some usage of the syntax in the real world to catch if there are any bugs. One bug was found and since fixed [here](winglang/wing#6277).
  • Loading branch information
Chriscbr authored Apr 22, 2024
1 parent e6a3d9d commit 29003a5
Show file tree
Hide file tree
Showing 48 changed files with 101 additions and 101 deletions.
2 changes: 1 addition & 1 deletion bedrock/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub class JokeMaker {
anthropic_version: "bedrock-2023-05-31"
});

return res.get("completion").asStr();
return res["completion"].asStr();
}
}
```
Expand Down
4 changes: 2 additions & 2 deletions bedrock/joke.w
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ pub class JokeMaker {
anthropic_version: "bedrock-2023-05-31"
});

return res.get("completion").asStr();
return res["completion"].asStr();
}
}
}
4 changes: 2 additions & 2 deletions bedrock/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bedrock/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@winglibs/bedrock",
"description": "A Wing library for Amazon Bedrock",
"version": "0.0.5",
"version": "0.0.6",
"author": {
"name": "Eyal Keren",
"email": "[email protected]"
Expand Down
4 changes: 2 additions & 2 deletions cognito/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cognito/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@winglibs/cognito",
"version": "0.0.7",
"version": "0.0.8",
"description": "A wing library to work with AWS Cognito",
"author": {
"name": "Elad Cohen",
Expand Down
10 changes: 5 additions & 5 deletions cognito/platform/sim.w
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ pub class Cognito_sim impl types.ICognito {
for entry in api.handlers.entries() {
let handler = entry.value;
let func: cloud.Function = handler.func;
let route = handler.mapping.eventProps.subscriptionProps.routes.at(0);
let route = handler.mapping.eventProps.subscriptionProps.routes[0];
if route.pathPattern == path && route.method == method.uppercase() {
let pathJson = MutJson api.apiSpec.get("paths").get(path);
let pathJson = MutJson api.apiSpec["paths"][path];
pathJson.set(method, unsafeCast(nil));

let api2: Json = unsafeCast(this.api);
Expand Down Expand Up @@ -154,7 +154,7 @@ pub class Cognito_sim impl types.ICognito {

this.table.update(email, {
"email": email,
"password": row!.get("password").asStr(),
"password": row!["password"].asStr(),
"confirmed": true,
});
}
Expand All @@ -165,11 +165,11 @@ pub class Cognito_sim impl types.ICognito {
throw "User not found";
}

if row!.get("email").asStr() != email || row!.get("password").asStr() != password {
if row!["email"].asStr() != email || row!["password"].asStr() != password {
throw "Invalid credentials";
}

if !row!.get("confirmed").asBool() {
if !row!["confirmed"].asBool() {
throw "User not confirmed";
}

Expand Down
4 changes: 2 additions & 2 deletions containers/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion containers/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@winglibs/containers",
"version": "0.0.27",
"version": "0.0.28",
"description": "Container support for Wing",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion containers/tfaws-vpc.w
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ pub class Vpc {
this.privateSubnets = vpc.get("private_subnets");
this.publicSubnets = vpc.get("public_subnets");
}
}
}
6 changes: 3 additions & 3 deletions containers/values.w
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ pub class Values {
if values != "undefined" {
for v in values.split(",") {
let kv = v.split("=");
let key = kv.at(0);
let value = kv.at(1);
let key = kv[0];
let value = kv[1];
all.set(key, value);
}
}
Expand All @@ -48,4 +48,4 @@ pub class Values {
throw "Missing platform value '{key}' (use --values or -v)";
}
}
}
}
2 changes: 1 addition & 1 deletion containers/workload.tfaws.w
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub class Workload_tfaws {
let envVariables = MutMap<plus.EnvValue>{};

for k in env.keys() {
if let v = env.get(k) {
if let v = env[k] {
envVariables.set(k, plus.EnvValue.fromValue(v));
}
}
Expand Down
4 changes: 2 additions & 2 deletions dynamodb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ test "put and query" {
ExpressionAttributeValues: {":id": "1"},
);
assert(response.Count == 1);
assert(response.Items.at(0).get("id").asStr() == "1");
assert(response.Items.at(0).get("body").asStr() == "hello");
assert(response.Items[0]["id"].asStr() == "1");
assert(response.Items[0]["body"].asStr() == "hello");
}
```

Expand Down
4 changes: 2 additions & 2 deletions dynamodb/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dynamodb/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@winglibs/dynamodb",
"version": "0.1.6",
"version": "0.1.7",
"description": "DynamoDB library for Wing",
"author": {
"name": "Cristian Pallarés",
Expand Down
8 changes: 4 additions & 4 deletions dynamodb/tests/compatibility.gsi.test.w
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ test "GlobalSecondaryIndex" {
];

for i in idCreated {
let id = i.get("id").asStr();
let createAt = i.get("createdAt").asNum();
let id = i["id"].asStr();
let createAt = i["createdAt"].asNum();

table.put({
Item: {
Expand Down Expand Up @@ -71,7 +71,7 @@ test "GlobalSecondaryIndex" {
// returns all items order by id desc
let ids = ["zuegksw", "pdkeruf", "dirnfhw", "azjekfw"];
for i in 0..ids.length {
assert(items.Items.at(i).get("id") == ids.at(i));
assert(items.Items[i]["id"] == ids[i]);
}

let itemsCreatedAtIndex = table.query(
Expand All @@ -91,6 +91,6 @@ test "GlobalSecondaryIndex" {
// returns all items order by createdAt desc
let idsOrderByCreatedAt = ["azjekfw", "pdkeruf", "dirnfhw", "zuegksw"];
for i in 0..idsOrderByCreatedAt.length {
assert(itemsCreatedAtIndex.Items.at(i).get("id") == idsOrderByCreatedAt.at(i));
assert(itemsCreatedAtIndex.Items[i]["id"] == idsOrderByCreatedAt[i]);
}
}
12 changes: 6 additions & 6 deletions dynamodb/tests/compatibility.query.test.w
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ test "query" {
);

assert(result.Count == 2);
assert(result.Items.at(0).get("k1") == "key1");
assert(result.Items.at(0).get("k2") == "value1");
assert(result.Items.at(0).get("k3") == "other-value1");
assert(result.Items.at(1).get("k1") == "key1");
assert(result.Items.at(1).get("k2") == "value2");
assert(result.Items.at(1).get("k3") == "other-value2");
assert(result.Items[0]["k1"] == "key1");
assert(result.Items[0]["k2"] == "value1");
assert(result.Items[0]["k3"] == "other-value1");
assert(result.Items[1]["k1"] == "key1");
assert(result.Items[1]["k2"] == "value2");
assert(result.Items[1]["k3"] == "other-value2");
}
2 changes: 1 addition & 1 deletion dynamodb/tests/delete.test.w
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ test "delete (`returnValues=ALL_OLD`)" {
ReturnValues: "ALL_OLD",
);

assert(response.Attributes?.get("body")?.asStr() == "hello world");
assert(response.Attributes?.tryGet("body")?.asStr() == "hello world");
}
2 changes: 1 addition & 1 deletion dynamodb/tests/put.test.w
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ test "put (`returnValues=ALL_OLD`)" {
ReturnValues: "ALL_OLD",
);

assert(response.Attributes?.get("body")?.asStr() == "hello world");
assert(response.Attributes?.tryGet("body")?.asStr() == "hello world");
}
12 changes: 6 additions & 6 deletions dynamodb/tests/query.test.w
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ test "query" {
ExpressionAttributeValues: {":id": "1"},
);
assert(response.Count == 2);
assert(response.Items.at(0).get("id").asStr() == "1");
assert(response.Items.at(0).get("sk").asStr() == "a");
assert(response.Items.at(0).get("body").asStr() == "hello a");
assert(response.Items.at(1).get("id").asStr() == "1");
assert(response.Items.at(1).get("sk").asStr() == "b");
assert(response.Items.at(1).get("body").asStr() == "hello b");
assert(response.Items[0]["id"].asStr() == "1");
assert(response.Items[0]["sk"].asStr() == "a");
assert(response.Items[0]["body"].asStr() == "hello a");
assert(response.Items[1]["id"].asStr() == "1");
assert(response.Items[1]["sk"].asStr() == "b");
assert(response.Items[1]["body"].asStr() == "hello b");
}
4 changes: 2 additions & 2 deletions dynamodb/tests/scan.test.w
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ test "scan" {

let response = table.scan();
assert(response.Count == 1);
assert(response.Items.at(0).get("id").asStr() == "1");
assert(response.Items.at(0).get("body").asStr() == "hello");
assert(response.Items[0]["id"].asStr() == "1");
assert(response.Items[0]["body"].asStr() == "hello");
}
8 changes: 4 additions & 4 deletions dynamodb/tests/transact-write.test.w
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ test "transactWrite (put)" {

let response = table.scan();
assert(response.Count == 1);
assert(response.Items.at(0).get("id").asStr() == "1");
assert(response.Items.at(0).get("body").asStr() == "hello");
assert(response.Items[0]["id"].asStr() == "1");
assert(response.Items[0]["body"].asStr() == "hello");
}

test "transactWrite (delete)" {
Expand Down Expand Up @@ -93,8 +93,8 @@ test "transactWrite (update)" {

let response = table.scan();
assert(response.Count == 1);
assert(response.Items.at(0).get("id").asStr() == "1");
assert(response.Items.at(0).get("body").asStr() == "world");
assert(response.Items[0]["id"].asStr() == "1");
assert(response.Items[0]["body"].asStr() == "world");
}

test "transactWrite (conditionCheck)" {
Expand Down
8 changes: 4 additions & 4 deletions eventbridge/lib.test.w
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ test "publish to eventbridge" {
log("after wait");
let published = types.Event.fromJson(github.bucket.getJson("test-0"));
expect.equal("pull-request.created", published.detailType);
expect.equal("test", published.resources.at(0));
expect.equal("test", published.resources[0]);
expect.equal("github.com", published.source);

expect.equal(0, env.bucket.list().length);
Expand All @@ -94,7 +94,7 @@ test "publish to eventbridge" {

// cant deserialize events coming from queue (see https://github.com/winglang/wing/issues/3686)
let published2 = env.bucket.getJson("environment");
expect.equal("myTest.check", published2.get("detail-type"));
expect.equal("test", published2.get("resources").getAt(0));
expect.equal("myTest", published2.get("source"));
expect.equal("myTest.check", published2["detail-type"]);
expect.equal("test", published2["resources"][0]);
expect.equal("myTest", published2["source"]);
}
4 changes: 2 additions & 2 deletions eventbridge/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion eventbridge/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@winglibs/eventbridge",
"description": "Amazon EventBridge library for Wing",
"version": "0.1.1",
"version": "0.1.2",
"repository": {
"type": "git",
"url": "https://github.com/winglang/winglibs.git",
Expand Down
4 changes: 2 additions & 2 deletions eventbridge/platform/sim/bus.w
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub class EventBridgeBus {
try {
let parsedEventRaw = Json.parse(event);
let jsonEvent = MutJson {
"detailType": parsedEventRaw.get("detail-type").asStr(),
"detailType": parsedEventRaw["detail-type"].asStr(),
};

for e in Json.entries(parsedEventRaw) {
Expand Down Expand Up @@ -76,4 +76,4 @@ pub class EventBridgeBus {
this.topic.publish(stringified);
}
}
}
}
4 changes: 2 additions & 2 deletions eventbridge/platform/sim/eventbridge.w
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub class Bus impl types.IBus {
let onMessageHandler = bus.subscribe(inflight (event) => {
let json: MutJson = event;
// make it look like it came from AWS
json.set("detail-type", json.get("detailType"));
json.set("detail-type", json["detailType"]);
json.set("detailType", unsafeCast(nil));
queue.push(Json.stringify(json));
}, pattern);
Expand All @@ -50,4 +50,4 @@ pub class Bus impl types.IBus {
pub inflight putEvents(events: Array<types.PublishEvent>): void {
this.bus.putEvents(events);
}
}
}
6 changes: 3 additions & 3 deletions github/lib.w
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ pub class ProbotApp {
throw "getVerifyProps: missing id header";
}

let id = lowkeysHeaders.get("x-github-delivery");
let id = lowkeysHeaders["x-github-delivery"];

if !lowkeysHeaders.has("x-github-event") {
throw "getVerifyProps: missing name header";
}

let name = lowkeysHeaders.get("x-github-event");
let name = lowkeysHeaders["x-github-event"];

let signature = lowkeysHeaders.get("x-hub-signature-256");
let signature = lowkeysHeaders["x-hub-signature-256"];

if let payload = req.body {
return {
Expand Down
Loading

0 comments on commit 29003a5

Please sign in to comment.