bson.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.resolveBSONOptions = exports.pluckBSONSerializeOptions = exports.Timestamp = exports.ObjectId = exports.MinKey = exports.MaxKey = exports.Map = exports.Long = exports.Int32 = exports.Double = exports.Decimal128 = exports.DBRef = exports.Code = exports.BSONSymbol = exports.BSONRegExp = exports.Binary = exports.calculateObjectSize = exports.serialize = exports.deserialize = void 0;
  4. // eslint-disable-next-line @typescript-eslint/no-var-requires
  5. let BSON = require('bson');
  6. try {
  7. // Ensure you always wrap an optional require in the try block NODE-3199
  8. BSON = require('bson-ext');
  9. }
  10. catch { } // eslint-disable-line
  11. /** @internal */
  12. exports.deserialize = BSON.deserialize;
  13. /** @internal */
  14. exports.serialize = BSON.serialize;
  15. /** @internal */
  16. exports.calculateObjectSize = BSON.calculateObjectSize;
  17. var bson_1 = require("bson");
  18. Object.defineProperty(exports, "Binary", { enumerable: true, get: function () { return bson_1.Binary; } });
  19. Object.defineProperty(exports, "BSONRegExp", { enumerable: true, get: function () { return bson_1.BSONRegExp; } });
  20. Object.defineProperty(exports, "BSONSymbol", { enumerable: true, get: function () { return bson_1.BSONSymbol; } });
  21. Object.defineProperty(exports, "Code", { enumerable: true, get: function () { return bson_1.Code; } });
  22. Object.defineProperty(exports, "DBRef", { enumerable: true, get: function () { return bson_1.DBRef; } });
  23. Object.defineProperty(exports, "Decimal128", { enumerable: true, get: function () { return bson_1.Decimal128; } });
  24. Object.defineProperty(exports, "Double", { enumerable: true, get: function () { return bson_1.Double; } });
  25. Object.defineProperty(exports, "Int32", { enumerable: true, get: function () { return bson_1.Int32; } });
  26. Object.defineProperty(exports, "Long", { enumerable: true, get: function () { return bson_1.Long; } });
  27. Object.defineProperty(exports, "Map", { enumerable: true, get: function () { return bson_1.Map; } });
  28. Object.defineProperty(exports, "MaxKey", { enumerable: true, get: function () { return bson_1.MaxKey; } });
  29. Object.defineProperty(exports, "MinKey", { enumerable: true, get: function () { return bson_1.MinKey; } });
  30. Object.defineProperty(exports, "ObjectId", { enumerable: true, get: function () { return bson_1.ObjectId; } });
  31. Object.defineProperty(exports, "Timestamp", { enumerable: true, get: function () { return bson_1.Timestamp; } });
  32. function pluckBSONSerializeOptions(options) {
  33. const { fieldsAsRaw, promoteValues, promoteBuffers, promoteLongs, serializeFunctions, ignoreUndefined, bsonRegExp, raw, enableUtf8Validation } = options;
  34. return {
  35. fieldsAsRaw,
  36. promoteValues,
  37. promoteBuffers,
  38. promoteLongs,
  39. serializeFunctions,
  40. ignoreUndefined,
  41. bsonRegExp,
  42. raw,
  43. enableUtf8Validation
  44. };
  45. }
  46. exports.pluckBSONSerializeOptions = pluckBSONSerializeOptions;
  47. /**
  48. * Merge the given BSONSerializeOptions, preferring options over the parent's options, and
  49. * substituting defaults for values not set.
  50. *
  51. * @internal
  52. */
  53. function resolveBSONOptions(options, parent) {
  54. var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
  55. const parentOptions = parent === null || parent === void 0 ? void 0 : parent.bsonOptions;
  56. return {
  57. raw: (_b = (_a = options === null || options === void 0 ? void 0 : options.raw) !== null && _a !== void 0 ? _a : parentOptions === null || parentOptions === void 0 ? void 0 : parentOptions.raw) !== null && _b !== void 0 ? _b : false,
  58. promoteLongs: (_d = (_c = options === null || options === void 0 ? void 0 : options.promoteLongs) !== null && _c !== void 0 ? _c : parentOptions === null || parentOptions === void 0 ? void 0 : parentOptions.promoteLongs) !== null && _d !== void 0 ? _d : true,
  59. promoteValues: (_f = (_e = options === null || options === void 0 ? void 0 : options.promoteValues) !== null && _e !== void 0 ? _e : parentOptions === null || parentOptions === void 0 ? void 0 : parentOptions.promoteValues) !== null && _f !== void 0 ? _f : true,
  60. promoteBuffers: (_h = (_g = options === null || options === void 0 ? void 0 : options.promoteBuffers) !== null && _g !== void 0 ? _g : parentOptions === null || parentOptions === void 0 ? void 0 : parentOptions.promoteBuffers) !== null && _h !== void 0 ? _h : false,
  61. ignoreUndefined: (_k = (_j = options === null || options === void 0 ? void 0 : options.ignoreUndefined) !== null && _j !== void 0 ? _j : parentOptions === null || parentOptions === void 0 ? void 0 : parentOptions.ignoreUndefined) !== null && _k !== void 0 ? _k : false,
  62. bsonRegExp: (_m = (_l = options === null || options === void 0 ? void 0 : options.bsonRegExp) !== null && _l !== void 0 ? _l : parentOptions === null || parentOptions === void 0 ? void 0 : parentOptions.bsonRegExp) !== null && _m !== void 0 ? _m : false,
  63. serializeFunctions: (_p = (_o = options === null || options === void 0 ? void 0 : options.serializeFunctions) !== null && _o !== void 0 ? _o : parentOptions === null || parentOptions === void 0 ? void 0 : parentOptions.serializeFunctions) !== null && _p !== void 0 ? _p : false,
  64. fieldsAsRaw: (_r = (_q = options === null || options === void 0 ? void 0 : options.fieldsAsRaw) !== null && _q !== void 0 ? _q : parentOptions === null || parentOptions === void 0 ? void 0 : parentOptions.fieldsAsRaw) !== null && _r !== void 0 ? _r : {},
  65. enableUtf8Validation: (_t = (_s = options === null || options === void 0 ? void 0 : options.enableUtf8Validation) !== null && _s !== void 0 ? _s : parentOptions === null || parentOptions === void 0 ? void 0 : parentOptions.enableUtf8Validation) !== null && _t !== void 0 ? _t : true
  66. };
  67. }
  68. exports.resolveBSONOptions = resolveBSONOptions;
  69. //# sourceMappingURL=bson.js.map