bson 5.0.1 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -13,7 +13,7 @@
13
13
  "etc/prepare.js"
14
14
  ],
15
15
  "types": "bson.d.ts",
16
- "version": "5.0.1",
16
+ "version": "5.1.0",
17
17
  "author": {
18
18
  "name": "The MongoDB NodeJS Team",
19
19
  "email": "dbx-node@mongodb.com"
@@ -17,7 +17,7 @@ import { Long } from './long';
17
17
  import { MaxKey } from './max_key';
18
18
  import { MinKey } from './min_key';
19
19
  import { ObjectId } from './objectid';
20
- import { isDate, isRegExp } from './parser/utils';
20
+ import { isDate, isRegExp, isMap } from './parser/utils';
21
21
  import { BSONRegExp } from './regexp';
22
22
  import { BSONSymbol } from './symbol';
23
23
  import { Timestamp } from './timestamp';
@@ -190,6 +190,18 @@ function getISOString(date: Date) {
190
190
 
191
191
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
192
192
  function serializeValue(value: any, options: EJSONSerializeOptions): any {
193
+ if (value instanceof Map || isMap(value)) {
194
+ const obj: Record<string, unknown> = Object.create(null);
195
+ for (const [k, v] of value) {
196
+ if (typeof k !== 'string') {
197
+ throw new BSONError('Can only serialize maps with string keys');
198
+ }
199
+ obj[k] = v;
200
+ }
201
+
202
+ return serializeValue(obj, options);
203
+ }
204
+
193
205
  if ((typeof value === 'object' || typeof value === 'function') && value !== null) {
194
206
  const index = options.seenObjects.findIndex(entry => entry.obj === value);
195
207
  if (index !== -1) {