MatthewWid / better-sse

⬆ Dead simple, dependency-less, spec-compliant server-sent events implementation for Node, written in TypeScript.
MIT License
485 stars 14 forks source link

Update ID generation to use the native UUID generation function #30

Closed MatthewWid closed 2 years ago

MatthewWid commented 2 years ago

Update the generateId utility function to use the new Node crypto generateUUID function. In addition, allow the user to override the default ID generation mechanism in the Session and Channel constructor options.

This has been benchmarked as having a significant performance improvement over using randomBytes: 129,016 opcs/sec -> 193,527 ops/sec.

Note that this will technically be a breaking change as it bumps the minimum Node version to v14.7.0 and also breaks the API contract that the event ID matches the Regex a-z0-9. However, seeing as Node 12 (the last maintained last version before Node 14) will reach end-of-life in three months, the user is able to override the event ID generation, and the unlikelihood that users are actually relying on the format of the default event ID string contents, I don't believe it will be much of an issue.