Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

feat: recursive metadata structure #285

Merged
merged 5 commits into from
Oct 6, 2022
Merged

feat: recursive metadata structure #285

merged 5 commits into from
Oct 6, 2022

Conversation

tjjfvi
Copy link
Contributor

@tjjfvi tjjfvi commented Oct 5, 2022

Resolves #284

  • There is an associated issue (required)
  • The change is described in detail
  • There are new or updated tests validating the change (if applicable)

Description

This changes the structure of the metadata to be recursive; where before compound types would reference other types via indices, they now reference the type object itself directly. This uses the new context api in scale v0.6.0 to decode directly into this structure, without any need for post-processing.

This eliminates almost all cases where one would need to index into the metadata.tys array, cleaning up the code significantly.

The only part that became more complicated was Metadata.test.ts. Though Deno's snapshot serializer does support circular references, it only uses references to parent objects in the circularity. This meant that it produced a – though finite – pathologically large string, as each type was written in expanded form potentially hundreds of times. To resolve this, Metadata.test.ts now has custom logic to serialize the metadata in a less pathological way. It's currently not exported anywhere, but it could be in the future – though I don't think this would necessarily be of value anywhere else.

If one decodes with the $ty codec standalone (i.e. not by way of $tys or $metadata), it will not have a way to get the types references by the indices in the buffer, so it will instead decode them as dummy objects with an appropriate id field. Though this is not type-safe, I think this is the best middleground.

@tjjfvi tjjfvi marked this pull request as ready for review October 6, 2022 15:15
@tjjfvi tjjfvi requested a review from harrysolovay as a code owner October 6, 2022 15:15
@tjjfvi tjjfvi merged commit 9b7b4c2 into main Oct 6, 2022
@tjjfvi tjjfvi deleted the update-scale branch October 6, 2022 15:47
harrysolovay pushed a commit that referenced this pull request Oct 19, 2022
harrysolovay pushed a commit that referenced this pull request Oct 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update FRAME Metadata Structure
2 participants