-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for byte translation #230
Open
MOmarMiraj
wants to merge
26
commits into
1Password:main
Choose a base branch
from
MOmarMiraj:omar/add-typeshare-byte-translation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add support for byte translation #230
MOmarMiraj
wants to merge
26
commits into
1Password:main
from
MOmarMiraj:omar/add-typeshare-byte-translation
+305
−61
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hculea
reviewed
Feb 19, 2025
hculea
reviewed
Feb 19, 2025
hculea
reviewed
Feb 19, 2025
hculea
reviewed
Feb 19, 2025
hculea
reviewed
Feb 19, 2025
hculea
reviewed
Feb 19, 2025
hculea
reviewed
Feb 19, 2025
hculea
reviewed
Feb 19, 2025
hculea
reviewed
Feb 19, 2025
hculea
reviewed
Feb 19, 2025
hculea
reviewed
Feb 19, 2025
…nctions and update tests
hculea
reviewed
Feb 19, 2025
…instead of struct level
hculea
reviewed
Feb 20, 2025
hculea
reviewed
Feb 20, 2025
hculea
reviewed
Feb 20, 2025
hculea
reviewed
Feb 20, 2025
hculea
reviewed
Feb 20, 2025
hculea
reviewed
Feb 20, 2025
hculea
reviewed
Feb 20, 2025
hculea
reviewed
Feb 20, 2025
…m translation logic more scaleable
hculea
reviewed
Feb 21, 2025
hculea
reviewed
Feb 21, 2025
hculea
reviewed
Feb 21, 2025
hculea
reviewed
Feb 21, 2025
hculea
reviewed
Feb 21, 2025
hculea
reviewed
Feb 21, 2025
hculea
reviewed
Feb 21, 2025
hculea
reviewed
Feb 21, 2025
hculea
reviewed
Feb 21, 2025
hculea
reviewed
Feb 21, 2025
Comment on lines
+207
to
+211
SpecialRustType::Vec(rtype) => { | ||
// TODO: https://github.com/1Password/typeshare/issues/231 | ||
self.add_import("typing".to_string(), "List".to_string()); | ||
Ok(format!("List[{}]", self.format_type(rtype, generic_types)?)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This diff is now no longer needed right? It can have the same translation as Array and Slice
hculea
reviewed
Feb 21, 2025
Comment on lines
+94
to
+96
/// Whether or not to include the serialization/deserialzation functions for bytes. | ||
/// This by default should be false as unless the user expclitly wants to translate to its bytes | ||
/// representation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is no longer accurate
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR adds support for translating
Vec<u8>
to the appropriate byte translation for Go, Python, and Typescript.To maintain backwards compatibility, decided to opt against adding a
Bytes
inSpecialRustType
as there could be some devs translatingVec<u8>
into a non byte translation and will be a breaking change.There was two options I was considering when implementing this feature:
This option would allow us to use the existing decorators functionality to parse each specific field to determine whether or not we can translate it to its appropriate byte translation.
The issue with this implementation is it would cause a pretty big refactor as the
format_special_type
function does not have access to decorators and allowing the function to have access whether passing it as an argument or attaching it to each language struct as a field would be overly complex for achieving not the greatest result.The second option is what this PR does, which is take adavantage of the
type_mappings
field which allows us to use thetypeshare.toml
to translate theVec<u8>
to its appropriate translation in each target language. This way is the least complex and is backwards compatible as the user would have to specify inside thetypeshare.toml
if they want the byte translation otherwise it would keep the current implementation intact.I added some tests in Go, Python, and Typescript to test this out.
With typescript, as there is no native support for
Uint8Array
for JSON serialization/deserialization, we have to add thesereviver
andreplacer
functions to not lose context of theUint8Array
during serialization/deserialization and the same thing goes for the Python implementation.