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/lib/bson.bundle.js +10 -0
- package/lib/bson.bundle.js.map +1 -1
- package/lib/bson.cjs +10 -0
- package/lib/bson.cjs.map +1 -1
- package/lib/bson.mjs +10 -0
- package/lib/bson.mjs.map +1 -1
- package/package.json +1 -1
- package/src/extended_json.ts +13 -1
package/package.json
CHANGED
package/src/extended_json.ts
CHANGED
|
@@ -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) {
|