-
Notifications
You must be signed in to change notification settings - Fork 257
feat!(NODE-4802): Refactor BSON to work with cross platform JS APIs #518
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
Changes from all commits
36f8a76
7923f93
08f18de
0368a0a
2abab0c
beb9baf
d1eb20a
3a752ab
252fff1
a93296b
15b386d
22f319f
4a0f911
35e0cfd
314a93e
73cb466
2b39966
f17e6dc
1d4194b
cd461a6
8716670
236deea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
{ | ||
"extends": "@istanbuljs/nyc-config-typescript", | ||
"include": [ | ||
"src/**/*" | ||
], | ||
"reporter": [ | ||
"lcovonly", | ||
"text-summary", | ||
"html" | ||
], | ||
"statements": 53, | ||
"branches": 38, | ||
"functions": 52, | ||
"lines": 54 | ||
"statements": 81, | ||
"branches": 73, | ||
"functions": 74, | ||
"lines": 83 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Changes in v5 | ||
|
||
## About | ||
|
||
The following is a detailed collection of the changes in the major v5 release of the bson package | ||
for nodejs and web platforms. | ||
|
||
<!-- | ||
1. a brief statement of what is breaking (brief as in "x will now return y instead of z", or "x is no longer supported, use y instead", etc | ||
2. a brief statement of why we are breaking it (bug, not useful, inconsistent behavior, better alternative, etc) | ||
3. if applicable, an example of suggested syntax change (can be included in (1) ) | ||
--> | ||
|
||
### Remove reliance on Node.js Buffer | ||
|
||
> **TL;DR**: Web environments return Uint8Array; Node.js environments return Buffer | ||
|
||
For those that use the BSON library on Node.js, there is no change - the BSON APIs will still return and accept instances of Node.js Buffer. Since we no longer depend on the Buffer web shim for compatibility with browsers, in non-Node.js environments a Uint8Array will be returned instead. | ||
|
||
This allows the BSON library to be better at platform independence while keeping its behavior consistent cross platform. The Buffer shim served the library well but brought in more than was necessary for the concerns of the code here. | ||
|
||
### `ObjectId.toString` / `UUID.toString` / `Binary.toString` | ||
|
||
> **TL;DR**: These `toString` methods only support the following encodings: 'hex', 'base64', 'utf8' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if the 'utf8' encoding isn't supported on I actually think that what you currently have as a "tl;dr" can be simply the sub-heading for the corresponding set of changes. I think it would also make the table of contents easier to generate. In the case of this TL;DR, it can be removed entirely if you update L22 the way I am suggesting; then the paragraph underneath can elaborate on the specifics Then the TL;DR of the section above (L16) can be promoted to a subheading, with both of these sections being under the title "Remove reliance on Node.js buffer", which would be the grouping heading. So in this guide, the grouping headings will indicate the themes of the changes, and the subheadings in the groups will be the actual breaking change from the user's perspective. (What I mean is, "remove reliance on nodejs buffer" isn't the breaking change, it's the cause of the breaking changes whose summaries follow) As for the 3rd example, I think we can group it under "Other" for now |
||
|
||
The methods: `ObjectId.toString`, `UUID.toString`, and `Binary.toString` took encodings that were passed through to the Node.js Buffer API. As a result of no longer relying on the presence of `Buffer` we can no longer support [every encoding that Node.js does](https://nodejs.org/dist/latest-v16.x/docs/api/buffer.html#buffers-and-character-encodings). We continue to support `'hex'` and `'base64'` on all three methods and additionally `'utf-8' | 'utf8'` on `Binary.toString`. If any of the other encodings are desired the underlying buffer for all these classes are publicly accessible and while in Node.js will be stored as a Node.js buffer: | ||
|
||
##### Migration Example: | ||
|
||
```typescript | ||
// Given Binary constructed from one of the encodings (using 'utf16le' as an example here) | ||
// no longer supported directly by the Binary.toString method | ||
const bin = new Binary(Buffer.from('abc', 'utf16le'), 0); | ||
// To obtain the original translation of bytes to string | ||
// We can access the underlying buffer and on Node.js it will be an instanceof Buffer | ||
// so it will support the translation to the specified encoding. | ||
bin.value(true).toString('utf16le'); | ||
// In web environments (and Node.js) the same can be accomplished with TextDecoder | ||
new TextDecoder('utf-16le').decode(bin.value(true)); | ||
``` | ||
|
||
### `serializeFunctions` bug fix | ||
|
||
> **TL;DR**: TODO | ||
|
||
TODO(NODE-4771): serializeFunctions bug fix makes function names outside the ascii range get serialized correctly |
This file was deleted.
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.