bson.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.toUTF8 = exports.getBigInt64LE = exports.getFloat64LE = exports.getInt32LE = exports.UUID = exports.Timestamp = exports.serialize = exports.ObjectId = exports.MinKey = exports.MaxKey = exports.Long = exports.Int32 = exports.EJSON = exports.Double = exports.deserialize = exports.Decimal128 = exports.DBRef = exports.Code = exports.calculateObjectSize = exports.BSONType = exports.BSONSymbol = exports.BSONRegExp = exports.BSONError = exports.BSON = exports.Binary = void 0;
  4. exports.parseToElementsToArray = parseToElementsToArray;
  5. exports.pluckBSONSerializeOptions = pluckBSONSerializeOptions;
  6. exports.resolveBSONOptions = resolveBSONOptions;
  7. exports.parseUtf8ValidationOption = parseUtf8ValidationOption;
  8. /* eslint-disable no-restricted-imports */
  9. const bson_1 = require("bson");
  10. var bson_2 = require("bson");
  11. Object.defineProperty(exports, "Binary", { enumerable: true, get: function () { return bson_2.Binary; } });
  12. Object.defineProperty(exports, "BSON", { enumerable: true, get: function () { return bson_2.BSON; } });
  13. Object.defineProperty(exports, "BSONError", { enumerable: true, get: function () { return bson_2.BSONError; } });
  14. Object.defineProperty(exports, "BSONRegExp", { enumerable: true, get: function () { return bson_2.BSONRegExp; } });
  15. Object.defineProperty(exports, "BSONSymbol", { enumerable: true, get: function () { return bson_2.BSONSymbol; } });
  16. Object.defineProperty(exports, "BSONType", { enumerable: true, get: function () { return bson_2.BSONType; } });
  17. Object.defineProperty(exports, "calculateObjectSize", { enumerable: true, get: function () { return bson_2.calculateObjectSize; } });
  18. Object.defineProperty(exports, "Code", { enumerable: true, get: function () { return bson_2.Code; } });
  19. Object.defineProperty(exports, "DBRef", { enumerable: true, get: function () { return bson_2.DBRef; } });
  20. Object.defineProperty(exports, "Decimal128", { enumerable: true, get: function () { return bson_2.Decimal128; } });
  21. Object.defineProperty(exports, "deserialize", { enumerable: true, get: function () { return bson_2.deserialize; } });
  22. Object.defineProperty(exports, "Double", { enumerable: true, get: function () { return bson_2.Double; } });
  23. Object.defineProperty(exports, "EJSON", { enumerable: true, get: function () { return bson_2.EJSON; } });
  24. Object.defineProperty(exports, "Int32", { enumerable: true, get: function () { return bson_2.Int32; } });
  25. Object.defineProperty(exports, "Long", { enumerable: true, get: function () { return bson_2.Long; } });
  26. Object.defineProperty(exports, "MaxKey", { enumerable: true, get: function () { return bson_2.MaxKey; } });
  27. Object.defineProperty(exports, "MinKey", { enumerable: true, get: function () { return bson_2.MinKey; } });
  28. Object.defineProperty(exports, "ObjectId", { enumerable: true, get: function () { return bson_2.ObjectId; } });
  29. Object.defineProperty(exports, "serialize", { enumerable: true, get: function () { return bson_2.serialize; } });
  30. Object.defineProperty(exports, "Timestamp", { enumerable: true, get: function () { return bson_2.Timestamp; } });
  31. Object.defineProperty(exports, "UUID", { enumerable: true, get: function () { return bson_2.UUID; } });
  32. function parseToElementsToArray(bytes, offset) {
  33. const res = bson_1.BSON.onDemand.parseToElements(bytes, offset);
  34. return Array.isArray(res) ? res : [...res];
  35. }
  36. exports.getInt32LE = bson_1.BSON.onDemand.NumberUtils.getInt32LE;
  37. exports.getFloat64LE = bson_1.BSON.onDemand.NumberUtils.getFloat64LE;
  38. exports.getBigInt64LE = bson_1.BSON.onDemand.NumberUtils.getBigInt64LE;
  39. exports.toUTF8 = bson_1.BSON.onDemand.ByteUtils.toUTF8;
  40. function pluckBSONSerializeOptions(options) {
  41. const { fieldsAsRaw, useBigInt64, promoteValues, promoteBuffers, promoteLongs, serializeFunctions, ignoreUndefined, bsonRegExp, raw, enableUtf8Validation } = options;
  42. return {
  43. fieldsAsRaw,
  44. useBigInt64,
  45. promoteValues,
  46. promoteBuffers,
  47. promoteLongs,
  48. serializeFunctions,
  49. ignoreUndefined,
  50. bsonRegExp,
  51. raw,
  52. enableUtf8Validation
  53. };
  54. }
  55. /**
  56. * Merge the given BSONSerializeOptions, preferring options over the parent's options, and
  57. * substituting defaults for values not set.
  58. *
  59. * @internal
  60. */
  61. function resolveBSONOptions(options, parent) {
  62. const parentOptions = parent?.bsonOptions;
  63. return {
  64. raw: options?.raw ?? parentOptions?.raw ?? false,
  65. useBigInt64: options?.useBigInt64 ?? parentOptions?.useBigInt64 ?? false,
  66. promoteLongs: options?.promoteLongs ?? parentOptions?.promoteLongs ?? true,
  67. promoteValues: options?.promoteValues ?? parentOptions?.promoteValues ?? true,
  68. promoteBuffers: options?.promoteBuffers ?? parentOptions?.promoteBuffers ?? false,
  69. ignoreUndefined: options?.ignoreUndefined ?? parentOptions?.ignoreUndefined ?? false,
  70. bsonRegExp: options?.bsonRegExp ?? parentOptions?.bsonRegExp ?? false,
  71. serializeFunctions: options?.serializeFunctions ?? parentOptions?.serializeFunctions ?? false,
  72. fieldsAsRaw: options?.fieldsAsRaw ?? parentOptions?.fieldsAsRaw ?? {},
  73. enableUtf8Validation: options?.enableUtf8Validation ?? parentOptions?.enableUtf8Validation ?? true
  74. };
  75. }
  76. /** @internal */
  77. function parseUtf8ValidationOption(options) {
  78. const enableUtf8Validation = options?.enableUtf8Validation;
  79. if (enableUtf8Validation === false) {
  80. return { utf8: false };
  81. }
  82. return { utf8: { writeErrors: false } };
  83. }
  84. //# sourceMappingURL=bson.js.map