Open luixo opened 11 months ago
Hi @luixo! Can you elaborate on why you’re looking to cut out those superfluous fields in meta
? If it‘s because of bandwidth concerns, I recommend to check how much of a size impact they really have after going through gzip. meta
tends to be highly compressable.
If you still want to omit those bytes afterwards, you could traverse the object before passing it to SuperJSON and delete
all undefined fields.
I try to keep SuperJSON light on config, so I‘m always recommending user-land solutions first. Let me know if that works for you!
It's mostly DX. Going through a big amount of superfluous fields just feels.. sad.
so I‘m always recommending user-land solutions first
That would be great, actually. Can I override (through register function) a transformer for a type that already has a transformer? If yes - can I make a serializer emit nothing to meta?
Going through a big amount of superfluous fields just feels.. sad.
I get that feeling :D But I promise you, if you neatly tuck it away into its own little function, it will spark a little more joy, and the function will feel a sense of purpose in its life.
Jokes aside - I get it, but this is a matter of complexity on SuperJSON's end, and i'd like to keep that as low as possible.
Can I override (through register function) a transformer for a type that already has a transformer?
Going off the current implementation, it looks like custom-registered transformers are taking precedence over built-in transformers for undefined
:
So this should work, yes! If you end up using this, please send a pull request with a test for this, so we can make sure there's no regressions to it.
If yes - can I make a serializer emit nothing to meta?
Try it out and let us know what you found!
Try it out and let us know what you found!
I investigated the source code and found no way to omit transforming a non-deep object (which is not a plain object, array, map, set or registered class). Should it be added? Is it in the scope of this package to let objects change between serialization / deserialization?
Or should I do deep omitting of undefined values myself before feeding the object to superjson?
Hello, I'm using
superjson
in my project (withtRPC
) and there is a bunch of fields which are optional - hence emitting undefined in a server response going client-side. It resolves to emptiness injson
field, but a bunch ofundefined
s inmeta
which I don't actually need as I don't go through object props anywhere in my project. Can I turn off this transformation somehow? Can Iregister
an override over this type? If so - how can I make it be omitted?