From 3be27a031a9e907d1122934f486c4fa46ad930ef Mon Sep 17 00:00:00 2001 From: Chris Rybicki Date: Thu, 8 Feb 2024 11:07:56 -0500 Subject: [PATCH] chore: upgrade Wing version --- dynamodb.w | 47 +++++++++++++++++++++-------------------------- main.w | 9 ++++----- 2 files changed, 25 insertions(+), 31 deletions(-) diff --git a/dynamodb.w b/dynamodb.w index 8c3bbc4..57f777a 100644 --- a/dynamodb.w +++ b/dynamodb.w @@ -168,8 +168,8 @@ pub class DynamoDBTableAws { } pub class DynamoDBTable { - tableSim: DynamoDBTableSim?; - tableAws: DynamoDBTableAws?; + tableSim: DynamoDBTableSim; // TODO: this is actually optional + tableAws: DynamoDBTableAws; // TODO: this is actually optional new(props: DynamoDBTableProps) { let target = util.env("WING_TARGET"); @@ -185,12 +185,12 @@ pub class DynamoDBTable { pub onLift(host: std.IInflightHost, ops: Array) { // currently simulator does not require permissions // may change with https://github.com/winglang/wing/issues/3082 - if let tableAws = this.tableAws { + if let tableAws = unsafeCast(this.tableAws) { if let host = aws.Function.from(host) { if ops.contains("putItem") { host.addPolicyStatements(aws.PolicyStatement { actions: ["dynamodb:PutItem"], - resources: [tableAws.table.arn], + resources: [tableAws?.table?.arn], effect: aws.Effect.ALLOW, }); } @@ -198,7 +198,7 @@ pub class DynamoDBTable { if ops.contains("getItem") { host.addPolicyStatements(aws.PolicyStatement { actions: ["dynamodb:GetItem"], - resources: [tableAws.table.arn], + resources: [tableAws?.table?.arn], effect: aws.Effect.ALLOW, }); } @@ -206,7 +206,7 @@ pub class DynamoDBTable { if ops.contains("scan") { host.addPolicyStatements(aws.PolicyStatement { actions: ["dynamodb:Scan"], - resources: [tableAws.table.arn], + resources: [tableAws?.table?.arn], effect: aws.Effect.ALLOW, }); } @@ -216,34 +216,29 @@ pub class DynamoDBTable { pub inflight getItem(key: Map): Map? { assert(key.size() == 1); - if let tableSim = this.tableSim { - return tableSim.getItem(key); - } - if let tableAws = this.tableAws { - return tableAws.getItem(key); + let isSim = unsafeCast(this.tableSim) != nil; + if isSim { + return this.tableSim.getItem(key); + } else { + return this.tableAws.getItem(key); } - throw("no table instance found for getItem"); } pub inflight putItem(item: Map) { - if let tableSim = this.tableSim { - tableSim.putItem(item); - return; - } - if let tableAws = this.tableAws { - tableAws.putItem(item); - return; + let isSim = unsafeCast(this.tableSim) != nil; + if isSim { + this.tableSim.putItem(item); + } else { + this.tableAws.putItem(item); } - throw("no table instance found for putItem"); } pub inflight scan(): Array> { - if let tableSim = this.tableSim { - return tableSim.scan(); - } - if let tableAws = this.tableAws { - return tableAws.scan(); + let isSim = unsafeCast(this.tableSim) != nil; + if isSim { + return this.tableSim.scan(); + } else { + return this.tableAws.scan(); } - throw("no table instance found for scan"); } } diff --git a/main.w b/main.w index 48584c6..05934f1 100644 --- a/main.w +++ b/main.w @@ -185,12 +185,11 @@ let foods = [ new cloud.OnDeploy(inflight () => { for food in foods { if !store.getEntry(food)? { - continue; + store.setEntry(Entry { + name: food, + score: 1500, + }); } - store.setEntry(Entry { - name: food, - score: 1500, - }); } }) as "InitializeTable";