Skip to content

feat: snapshot read metadata response type and mapper#1079

Merged
peterpeterparker merged 3 commits intomainfrom
feat/snapshot-response
Oct 3, 2025
Merged

feat: snapshot read metadata response type and mapper#1079
peterpeterparker merged 3 commits intomainfrom
feat/snapshot-response

Conversation

@peterpeterparker
Copy link
Copy Markdown
Contributor

@peterpeterparker peterpeterparker commented Oct 3, 2025

Motivation

When I developed support for the read and upload snapshot feature in #1046, I was really hesitant about whether to parse/map the metadata response. On one hand, for consistency with the other functions in the module, we should not parse the response, since none of the other functions do so. On the other hand, we already use custom parameters for the exposed parts of the module, a pattern that should also apply when implementing the upload metadata of the snapshot.

Ultimately, I decided it would be more practical for the consumer to receive a mapped object when reading data. This way, the consumer can simply download a value and pass the same back on upload, without having to implement additional conversions on their side.

I validated this approach with my implementation in Juno's CLI (PR 382).

That said, I’m still not fully satisfied with it. Generally speaking, I hope we’ll find a solution in the future that makes both inputs and outputs consistent.

Changes

  • Define a response type to read metadata
  • Add a utility to parse candid types to custom js type
  • Expose new module to consumer

Notes

I exposed the all snapshot.response module in index.ts, not just the interface, for consistency reasons because we do so with the params.

Signed-off-by: David Dal Busco <david.dalbusco@dfinity.org>
@peterpeterparker peterpeterparker requested review from a team as code owners October 3, 2025 06:29
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Oct 3, 2025

size-limit report 📦

Path Size
@dfinity/ckbtc 8.15 KB (0%)
@dfinity/cketh 3.7 KB (0%)
@dfinity/cmc 1.39 KB (0%)
@dfinity/ledger-icrc 4.64 KB (0%)
@dfinity/ledger-icp 7.14 KB (0%)
@dfinity/nns 27.21 KB (0%)
@dfinity/nns-proto 140.99 KB (0%)
@dfinity/sns 19.06 KB (0%)
@dfinity/utils 5.1 KB (0%)
@dfinity/zod-schemas 621 B (0%)
@dfinity/ic-management 4.11 KB (+6.65% 🔺)

Signed-off-by: David Dal Busco <david.dalbusco@dfinity.org>
Copy link
Copy Markdown
Collaborator

@AntonioVentilii AntonioVentilii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM tks!

I left two suggestions, but up to you

Comment thread packages/ic-management/src/types/snapshot.responses.ts
Comment thread packages/ic-management/src/types/snapshot.responses.ts
Comment thread packages/ic-management/src/types/snapshot.responses.ts
@peterpeterparker peterpeterparker merged commit 7cdf7de into main Oct 3, 2025
16 checks passed
@peterpeterparker peterpeterparker deleted the feat/snapshot-response branch October 3, 2025 06:52
peterpeterparker added a commit that referenced this pull request Oct 3, 2025
# Motivation

A cool idea of @AntonioVentilii shared in this
[review](#1079 (comment)):
in addition to throwing when a variant is unknown, which can happens
when the did types are extended in the IC repo, we can also type the
rest to detect the issue at build time. Given there are various usage of
the pattern in ic-js, I thought that creating a reusable function can be
handy.

# Notes

I don't know how to actually implement a vitest that would passes the
build with an incompatible code. Thought it was kind of a quite an
effort so skipped that part.

That said we can assert it works out as implementing the function in nns
allows to detect that missing types are not implemented, see #1083.

# Changes

- Create `assertNever`

---------

Signed-off-by: David Dal Busco <david.dalbusco@dfinity.org>
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants