Skip to content

Commit

Permalink
chore: upgrade Wing version (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chriscbr authored Feb 8, 2024
1 parent 807dafb commit 18a02a5
Show file tree
Hide file tree
Showing 4 changed files with 258 additions and 270 deletions.
50 changes: 24 additions & 26 deletions dynamodb.w
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,11 @@ pub class DynamoDBTableAws {
}

pub class DynamoDBTable {
tableSim: DynamoDBTableSim?;
tableAws: DynamoDBTableAws?;
// TODO: these fields are actually optional. workaround for:
// https://github.com/winglang/wing/issues/5636
// https://github.com/winglang/wing/issues/5647
tableSim: DynamoDBTableSim;
tableAws: DynamoDBTableAws;

new(props: DynamoDBTableProps) {
let target = util.env("WING_TARGET");
Expand All @@ -185,28 +188,28 @@ pub class DynamoDBTable {
pub onLift(host: std.IInflightHost, ops: Array<str>) {
// 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,
});
}

if ops.contains("getItem") {
host.addPolicyStatements(aws.PolicyStatement {
actions: ["dynamodb:GetItem"],
resources: [tableAws.table.arn],
resources: [tableAws?.table?.arn],
effect: aws.Effect.ALLOW,
});
}

if ops.contains("scan") {
host.addPolicyStatements(aws.PolicyStatement {
actions: ["dynamodb:Scan"],
resources: [tableAws.table.arn],
resources: [tableAws?.table?.arn],
effect: aws.Effect.ALLOW,
});
}
Expand All @@ -216,34 +219,29 @@ pub class DynamoDBTable {

pub inflight getItem(key: Map<Attribute>): Map<Attribute>? {
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<Attribute>) {
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<Map<Attribute>> {
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");
}
}
9 changes: 4 additions & 5 deletions main.w
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
Loading

0 comments on commit 18a02a5

Please sign in to comment.