bson 7.1.1 → 7.2.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.cjs CHANGED
@@ -261,6 +261,11 @@ const nodeJsByteUtils = {
261
261
  concat(list) {
262
262
  return Buffer.concat(list);
263
263
  },
264
+ copy(source, target, targetStart, sourceStart, sourceEnd) {
265
+ return nodeJsByteUtils
266
+ .toLocalBufferType(source)
267
+ .copy(target, targetStart ?? 0, sourceStart ?? 0, sourceEnd ?? source.length);
268
+ },
264
269
  equals(a, b) {
265
270
  return nodeJsByteUtils.toLocalBufferType(a).equals(b);
266
271
  },
@@ -405,6 +410,27 @@ const webByteUtils = {
405
410
  }
406
411
  return result;
407
412
  },
413
+ copy(source, target, targetStart, sourceStart, sourceEnd) {
414
+ if (sourceEnd !== undefined && sourceEnd < 0) {
415
+ throw new RangeError(`The value of "sourceEnd" is out of range. It must be >= 0. Received ${sourceEnd}`);
416
+ }
417
+ sourceEnd = sourceEnd ?? source.length;
418
+ if (sourceStart !== undefined && (sourceStart < 0 || sourceStart > sourceEnd)) {
419
+ throw new RangeError(`The value of "sourceStart" is out of range. It must be >= 0 and <= ${sourceEnd}. Received ${sourceStart}`);
420
+ }
421
+ sourceStart = sourceStart ?? 0;
422
+ if (targetStart !== undefined && targetStart < 0) {
423
+ throw new RangeError(`The value of "targetStart" is out of range. It must be >= 0. Received ${targetStart}`);
424
+ }
425
+ targetStart = targetStart ?? 0;
426
+ const srcSlice = source.subarray(sourceStart, sourceEnd);
427
+ const maxLen = Math.min(srcSlice.length, target.length - targetStart);
428
+ if (maxLen <= 0) {
429
+ return 0;
430
+ }
431
+ target.set(srcSlice.subarray(0, maxLen), targetStart);
432
+ return maxLen;
433
+ },
408
434
  equals(uint8Array, otherUint8Array) {
409
435
  if (uint8Array.byteLength !== otherUint8Array.byteLength) {
410
436
  return false;
@@ -4310,7 +4336,7 @@ function serializeValue(value, options) {
4310
4336
  if (Array.isArray(value))
4311
4337
  return serializeArray(value, options);
4312
4338
  if (value === undefined)
4313
- return null;
4339
+ return options.ignoreUndefined ? undefined : null;
4314
4340
  if (value instanceof Date || isDate(value)) {
4315
4341
  const dateNum = value.getTime(), inRange = dateNum > -1 && dateNum < 253402318800000;
4316
4342
  if (options.legacy) {