-
-
Notifications
You must be signed in to change notification settings - Fork 12
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
fix(*): new serialization mechanism #1660
Conversation
This is kinda why I hate JS. I can't really just automatically assume serialization fields with async or can I just "return and forget" While this approach looks nice, you're basically just using classes. Why not just use classes instead of creating an entirely abstract interface + paying for the injection costs? Something like |
It's not a limitation of JS, it's class-transformer's one. The issue is reported, but it seems any kind of development is on hold for now, sadly. When it comes to your second question: yes, we could go for a full object-oriented approach, but it seems like pissing into the wind with NestJS' architecture. We would have to workaround the whole injection system, it looks... nasty? export class Game implements Serializable<GameDto> {
// ...
async serialize(): Promise<GameDto> {
const playersService = app.get(PlayersService); // this line here seems wrong
return {
// ...
players: Promise.all(this.players.map(async player => await (await playersService.getById(player)).serialize()),
// ...
};
}
} |
I mean, I'm not entirely against this approach, I just think it's a little bit more iffy... |
everything about serialization is stupid. |
That's a strong statement if I've ever seen one... |
On the other hand, |
@c43721 take a look now, does it look better to you? |
I actually like this newer approach. That's quite smart. |
Technically we can use intercepters and return instance of like some class (Serializable in our case) and do the |
That would require traversing deep through object to find instances of |
lol (it would be at most like 20ms additional time. You're using express- you don't care about performance. If you did, we'd be using fastify and not nest) |
9f968bc
to
d551c57
Compare
Codecov Report
@@ Coverage Diff @@
## master #1660 +/- ##
==========================================
+ Coverage 94.82% 95.00% +0.17%
==========================================
Files 221 219 -2
Lines 4388 4420 +32
Branches 436 445 +9
==========================================
+ Hits 4161 4199 +38
+ Misses 218 212 -6
Partials 9 9
Continue to review full report at Codecov.
|
@c43721 ready for review. The tests are a mess, don't look at them. |
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.
some nits, comments, and other things I found
Using class-transformer to serialize objects does not allow us to use async methods, thus rendering us incapable of resolving sub-documents properly. This PR attemps to approach object serialization another way, using proper services, some meta-types and injector.
Model changes:
Game.slot.player
is aPlayer
instance,Game.gameServer
is aGameServer
instance,QueueSlot.playerId
is gone