winglang/wing

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

Open

#6.555 geöffnet am 24. Mai 2024

Auf GitHub ansehen
 (1 Kommentar) (1 Reaktion) (0 zugewiesene Personen)TypeScript (214 Forks)github user discovery
Stalegood first issue✨ enhancement🎨 sdk

Repository-Metriken

Stars
 (5.385 Stars)
PR-Merge-Metriken
 (Keine gemergten PRs in 30 T)

Beschreibung

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