Skip to content

Commit

Permalink
chore: use indexing syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
Chriscbr committed Apr 19, 2024
1 parent 3afc7eb commit 4e48817
Show file tree
Hide file tree
Showing 38 changed files with 91 additions and 90 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();
}
}
}
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
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
12 changes: 6 additions & 6 deletions cognito/platform/sim.w
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@ 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);
let callable: ICallable = unsafeCast(api2?.get(method));
let callable: ICallable = unsafeCast(api2[method]);
callable.call(this.api, path, inflight (req: cloud.ApiRequest) => {
if req.headers?.tryGet("authorization") != "Bearer sim-auth-token" {
if this.counter.peek() % 2 == 0 {
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
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
14 changes: 7 additions & 7 deletions containers/tfaws-eks.w
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ pub class Cluster extends ClusterBase impl ICluster {
}

return ClusterAttributes {
name: values.Values.get("eks.cluster_name"),
certificate: values.Values.get("eks.certificate"),
endpoint: values.Values.get("eks.endpoint"),
name: values.Values["eks.cluster_name"],
certificate: values.Values["eks.certificate"],
endpoint: values.Values["eks.endpoint"],
};

}
Expand Down Expand Up @@ -167,11 +167,11 @@ pub class Cluster extends ClusterBase impl ICluster {

this._attributes = {
name: clusterName,
certificate: cluster.get("cluster_certificate_authority_data"),
endpoint: cluster.get("cluster_endpoint"),
certificate: cluster["cluster_certificate_authority_data"],
endpoint: cluster["cluster_endpoint"],
};

this._oidcProviderArn = cluster.get("oidc_provider_arn");
this._oidcProviderArn = cluster["oidc_provider_arn"];

// output the cluster name
new cdktf.TerraformOutput(value: this._attributes.name, description: "eks.cluster_name") as "eks.cluster_name";
Expand Down Expand Up @@ -216,7 +216,7 @@ pub class Cluster extends ClusterBase impl ICluster {
"app.kubernetes.io/component"=> "controller"
},
annotations: {
"eks.amazonaws.com/role-arn" => lbRole.get("iam_role_arn"),
"eks.amazonaws.com/role-arn" => lbRole["iam_role_arn"],
"eks.amazonaws.com/sts-regional-endpoints" => "true"
},
}
Expand Down
8 changes: 4 additions & 4 deletions containers/tfaws-vpc.w
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ pub class Vpc {
}
);

this.id = vpc.get("vpc_id");
this.privateSubnets = vpc.get("private_subnets");
this.publicSubnets = vpc.get("public_subnets");
this.id = vpc["vpc_id"];
this.privateSubnets = vpc["private_subnets"];
this.publicSubnets = vpc["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
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
9 changes: 5 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,8 @@ 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));
let x = items.Items[i]["id"];
assert(items.Items[i]["id"] == ids[i]);
}

let itemsCreatedAtIndex = table.query(
Expand All @@ -91,6 +92,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"]);
}
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
8 changes: 4 additions & 4 deletions github/ngrok/ngrok.w
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ pub class Ngrok {
while retries > 0 {
try {
let json = Json.parse(http.get("http://127.0.0.1:{ngrokAPIPort}/api/tunnels").body);
for tunnel in Json.values(json.get("tunnels")) {
let address = tunnel.get("config").get("addr").asStr();
for tunnel in Json.values(json["tunnels"]) {
let address = tunnel["config"]["addr"].asStr();
log("Checking {address}");
if address == props.url {
state.set("url", tunnel.get("public_url").asStr());
state.set("url", tunnel["public_url"].asStr());
return nil;
}
}
Expand All @@ -56,4 +56,4 @@ pub class Ngrok {
});
urlRetriever.node.addDependency(ngrok);
}
}
}
2 changes: 1 addition & 1 deletion github/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@winglibs/github",
"description": "A Wing library for GitHub Probot",
"version": "0.0.9",
"version": "0.0.10",
"author": {
"name": "Elad Cohen",
"email": "[email protected]"
Expand Down
Loading

0 comments on commit 4e48817

Please sign in to comment.