bson 7.1.0 → 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.mjs CHANGED
@@ -259,6 +259,11 @@ const nodeJsByteUtils = {
259
259
  concat(list) {
260
260
  return Buffer.concat(list);
261
261
  },
262
+ copy(source, target, targetStart, sourceStart, sourceEnd) {
263
+ return nodeJsByteUtils
264
+ .toLocalBufferType(source)
265
+ .copy(target, targetStart ?? 0, sourceStart ?? 0, sourceEnd ?? source.length);
266
+ },
262
267
  equals(a, b) {
263
268
  return nodeJsByteUtils.toLocalBufferType(a).equals(b);
264
269
  },
@@ -403,6 +408,27 @@ const webByteUtils = {
403
408
  }
404
409
  return result;
405
410
  },
411
+ copy(source, target, targetStart, sourceStart, sourceEnd) {
412
+ if (sourceEnd !== undefined && sourceEnd < 0) {
413
+ throw new RangeError(`The value of "sourceEnd" is out of range. It must be >= 0. Received ${sourceEnd}`);
414
+ }
415
+ sourceEnd = sourceEnd ?? source.length;
416
+ if (sourceStart !== undefined && (sourceStart < 0 || sourceStart > sourceEnd)) {
417
+ throw new RangeError(`The value of "sourceStart" is out of range. It must be >= 0 and <= ${sourceEnd}. Received ${sourceStart}`);
418
+ }
419
+ sourceStart = sourceStart ?? 0;
420
+ if (targetStart !== undefined && targetStart < 0) {
421
+ throw new RangeError(`The value of "targetStart" is out of range. It must be >= 0. Received ${targetStart}`);
422
+ }
423
+ targetStart = targetStart ?? 0;
424
+ const srcSlice = source.subarray(sourceStart, sourceEnd);
425
+ const maxLen = Math.min(srcSlice.length, target.length - targetStart);
426
+ if (maxLen <= 0) {
427
+ return 0;
428
+ }
429
+ target.set(srcSlice.subarray(0, maxLen), targetStart);
430
+ return maxLen;
431
+ },
406
432
  equals(uint8Array, otherUint8Array) {
407
433
  if (uint8Array.byteLength !== otherUint8Array.byteLength) {
408
434
  return false;
@@ -4308,7 +4334,7 @@ function serializeValue(value, options) {
4308
4334
  if (Array.isArray(value))
4309
4335
  return serializeArray(value, options);
4310
4336
  if (value === undefined)
4311
- return null;
4337
+ return options.ignoreUndefined ? undefined : null;
4312
4338
  if (value instanceof Date || isDate(value)) {
4313
4339
  const dateNum = value.getTime(), inRange = dateNum > -1 && dateNum < 253402318800000;
4314
4340
  if (options.legacy) {
@@ -4592,6 +4618,8 @@ function parseToElements(bytes, startOffset = 0) {
4592
4618
 
4593
4619
  const onDemand = Object.create(null);
4594
4620
  onDemand.parseToElements = parseToElements;
4621
+ onDemand.ByteUtils = ByteUtils;
4622
+ onDemand.NumberUtils = NumberUtils;
4595
4623
  Object.freeze(onDemand);
4596
4624
 
4597
4625
  const MAXSIZE = 1024 * 1024 * 17;