mongoose 8.6.2 → 8.6.4

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.
@@ -26,19 +26,6 @@ function hex2buffer(hex) {
26
26
  return buff;
27
27
  }
28
28
 
29
- /**
30
- * Helper function to convert the buffer input to a string
31
- * @param {Buffer} buf The buffer to convert to a hex-string
32
- * @returns {String} The buffer as a hex-string
33
- * @api private
34
- */
35
-
36
- function binary2hex(buf) {
37
- // use buffer built-in function to convert from buffer to hex-string
38
- const hex = buf != null && buf.toString('hex');
39
- return hex;
40
- }
41
-
42
29
  /**
43
30
  * Convert a String to Binary
44
31
  * @param {String} uuidStr The value to process
@@ -67,7 +54,7 @@ function binaryToString(uuidBin) {
67
54
  // i(hasezoey) dont quite know why, but "uuidBin" may sometimes also be the already processed string
68
55
  let hex;
69
56
  if (typeof uuidBin !== 'string' && uuidBin != null) {
70
- hex = binary2hex(uuidBin);
57
+ hex = uuidBin.toString('hex');
71
58
  const uuidStr = hex.substring(0, 8) + '-' + hex.substring(8, 8 + 4) + '-' + hex.substring(12, 12 + 4) + '-' + hex.substring(16, 16 + 4) + '-' + hex.substring(20, 20 + 12);
72
59
  return uuidStr;
73
60
  }
@@ -90,7 +77,15 @@ function SchemaUUID(key, options) {
90
77
  if (value != null && value.$__ != null) {
91
78
  return value;
92
79
  }
93
- return binaryToString(value);
80
+ if (Buffer.isBuffer(value)) {
81
+ return binaryToString(value);
82
+ } else if (value instanceof Binary) {
83
+ return binaryToString(value.buffer);
84
+ } else if (utils.isPOJO(value) && value.type === 'Buffer' && Array.isArray(value.data)) {
85
+ // Cloned buffers look like `{ type: 'Buffer', data: [5, 224, ...] }`
86
+ return binaryToString(Buffer.from(value.data));
87
+ }
88
+ return value;
94
89
  });
95
90
  }
96
91
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mongoose",
3
3
  "description": "Mongoose MongoDB ODM",
4
- "version": "8.6.2",
4
+ "version": "8.6.4",
5
5
  "author": "Guillermo Rauch <guillermo@learnboost.com>",
6
6
  "keywords": [
7
7
  "mongodb",
@@ -138,7 +138,7 @@ declare module 'mongoose' {
138
138
  * Takes a populated field and returns it to its unpopulated state. If called with
139
139
  * no arguments, then all populated fields are returned to their unpopulated state.
140
140
  */
141
- depopulate(path?: string | string[]): this;
141
+ depopulate<Paths = {}>(path?: string | string[]): MergeType<this, Paths>;
142
142
 
143
143
  /**
144
144
  * Returns the list of paths that have been directly modified. A direct