vanita5 / mastodon-api

Mastodon API Client Library
MIT License
122 stars 21 forks source link

Parser emits number for delete events, which get rounded to numbers beyond MAX_SAFE_INTEGER #34

Open fasiha opened 1 year ago

fasiha commented 1 year ago

I was debugging why I was being notified of deleted statuses whose IDs I didn't recognize. For example, I received the following payload from the mastodon-api message listener:

{ event: 'delete', data: 110988663231921360 }

Note that this is a number (even though Mastodon streaming API docs claim it should be a string ID). However, if in parser.js I console.log the raw message, here's what it receives:

event: delete\ndata: 110988663231921363\n\n

110988663231921363 (≈2**56.623) is bigger than MAX_SAFE_INTEGER so it gets rounded to the value coming out of the message listener:

> parseInt('110988663231921363')
110988663231921360

Note how the two numbers above aren't the same.


Do you have any tips on how the parser should be modified to handle this special case? Should we have a list of events that need to be treated as strings (like delete) and pass that through as-is without any JSON decoding?