winglang/wing

`Counter.keys()` and `Counter.entries()` methods

Open

#6,555 opened on May 24, 2024

View on GitHub
 (1 comment) (1 reaction) (0 assignees)TypeScript (214 forks)github user discovery
Stalegood first issue✨ enhancement🎨 sdk

Repository metrics

Stars
 (5,385 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

Use Case

To visualize the entire state of Counter (https://github.com/winglang/wing/issues/6100), you need to have some way to find out what keys have values stored

Proposed Solution

bring cloud;

let c = new cloud.Counter();

test "obtain counter's keys" {
  expect.equal(c.keys() == ["default"]);
  c.inc();
  expect.equal(c.keys() == ["default"]);
  c.inc(1, "my-key");
  expect.equal(c.keys() == ["default", "my-key"]);
}

Alternative:

bring cloud;

let c = new cloud.Counter();

test "obtain counter's keys" {
  expect.equal(c.entries() == [CounterEntry { key: "default", value: 0 }]);
  c.inc();
  expect.equal(c.entries() == [CounterEntry { key: "default", value: 1 }]);
  c.inc(1, "my-key");
  expect.equal(c.entries() == [CounterEntry { key: "default", value: 1 }, CounterEntry { key: "my-key", value: 1 }]);
}

Implementation Notes

For AWS targets which implement Counter using DynamoDB, it might be possible to implement these with the Scan operation

Component

SDK

Community Notes

  • Please vote by adding a 👍 reaction to the issue to help us prioritize.
  • If you are interested to work on this issue, please leave a comment.
  • If this issue is labeled needs-discussion, it means the spec has not been finalized yet. Please reach out on the #dev channel in the Wing Discord.

Contributor guide