Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: upgrade Wing version #27

Merged
merged 3 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading