winglang/wing

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

Open

#6555 aperta il 24 mag 2024

Vedi su GitHub
 (1 commento) (1 reazione) (0 assegnatari)TypeScript (214 fork)github user discovery
Stalegood first issue✨ enhancement🎨 sdk

Metriche repository

Star
 (5385 star)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

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.

Guida contributor