You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* If you import BSON commonjs style `const BSON = require('bson')` then the `BSON.default` property is no longer present.
186
187
* If you import BSON esmodule style `import BSON from 'bson'` then this code will crash upon loading. **TODO: This is not the case right now but it will be after NODE-4713.**
187
188
* This error will throw: `SyntaxError: The requested module 'bson' does not provide an export named 'default'`.
189
+
190
+
### `class Code` always converts `.code` to string
191
+
192
+
The `Code` class still supports the same constructor arguments as before.
193
+
It will now convert the first argument to a string before saving it to the code property, see the following:
194
+
195
+
```typescript
196
+
const myCode =newCode(function iLoveJavascript() { console.log('I love javascript') });
197
+
// myCode.code === "function iLoveJavascript() { console.log('I love javascript') }"
198
+
// typeof myCode.code === 'string'
199
+
```
200
+
201
+
### `BSON.deserialize()` only returns `Code` instances
202
+
203
+
The deserialize options: `evalFunctions`, `cacheFunctions`, and `cacheFunctionsCrc32` have been removed.
204
+
The `evalFunctions` option, when enabled, would return BSON Code typed values as eval-ed javascript functions, now it will always return Code instances.
205
+
206
+
See the following snippet for how to migrate:
207
+
```typescript
208
+
const bsonBytes =BSON.serialize(
209
+
{ iLoveJavascript: function () { console.log('I love javascript') } },
210
+
{ serializeFunctions: true } // serializeFunctions still works!
211
+
);
212
+
const result =BSON.deserialize(bsonBytes)
213
+
// result.iLoveJavascript instanceof Code
214
+
// result.iLoveJavascript.code === "function () { console.log('I love javascript') }"
0 commit comments