winglang/wing

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

Open

#6,555 建立於 2024年5月24日

在 GitHub 查看
 (1 留言) (1 反應) (0 負責人)TypeScript (214 fork)github user discovery
Stalegood first issue✨ enhancement🎨 sdk

倉庫指標

Star
 (5,385 star)
PR 合併指標
 (30 天內沒有已合併 PR)

描述

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.

貢獻者指南