This repository has been archived by the owner on Sep 14, 2023. It is now read-only.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves #284
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 appropriateid
field. Though this is not type-safe, I think this is the best middleground.