mongoose 8.14.0 → 8.14.1

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.
@@ -81,6 +81,8 @@ function assignRawDocsToIdStructure(rawIds, resultDocs, resultOrder, options, re
81
81
  if (id?.constructor?.name === 'Binary' && id.sub_type === 4 && typeof id.toUUID === 'function') {
82
82
  // Workaround for gh-15315 because Mongoose UUIDs don't use BSON UUIDs yet.
83
83
  sid = String(id.toUUID());
84
+ } else if (id?.constructor?.name === 'Buffer' && id._subtype === 4 && typeof id.toUUID === 'function') {
85
+ sid = String(id.toUUID());
84
86
  } else {
85
87
  sid = String(id);
86
88
  }
package/lib/model.js CHANGED
@@ -4688,7 +4688,14 @@ function _assign(model, vals, mod, assignmentOpts) {
4688
4688
  if (__val instanceof Document) {
4689
4689
  __val = __val._doc._id;
4690
4690
  }
4691
- key = String(__val);
4691
+ if (__val?.constructor?.name === 'Binary' && __val.sub_type === 4 && typeof __val.toUUID === 'function') {
4692
+ // Workaround for gh-15315 because Mongoose UUIDs don't use BSON UUIDs yet.
4693
+ key = String(__val.toUUID());
4694
+ } else if (__val?.constructor?.name === 'Buffer' && __val._subtype === 4 && typeof __val.toUUID === 'function') {
4695
+ key = String(__val.toUUID());
4696
+ } else {
4697
+ key = String(__val);
4698
+ }
4692
4699
  if (rawDocs[key]) {
4693
4700
  if (Array.isArray(rawDocs[key])) {
4694
4701
  rawDocs[key].push(val);
@@ -4711,7 +4718,14 @@ function _assign(model, vals, mod, assignmentOpts) {
4711
4718
  if (_val instanceof Document) {
4712
4719
  _val = _val._doc._id;
4713
4720
  }
4714
- key = String(_val);
4721
+ if (_val?.constructor?.name === 'Binary' && _val.sub_type === 4 && typeof _val.toUUID === 'function') {
4722
+ // Workaround for gh-15315 because Mongoose UUIDs don't use BSON UUIDs yet.
4723
+ key = String(_val.toUUID());
4724
+ } else if (_val?.constructor?.name === 'Buffer' && _val._subtype === 4 && typeof _val.toUUID === 'function') {
4725
+ key = String(_val.toUUID());
4726
+ } else {
4727
+ key = String(_val);
4728
+ }
4715
4729
  if (rawDocs[key]) {
4716
4730
  if (Array.isArray(rawDocs[key])) {
4717
4731
  rawDocs[key].push(val);
package/lib/schema/map.js CHANGED
@@ -23,12 +23,12 @@ class SchemaMap extends SchemaType {
23
23
  return SchemaType.set(option, value);
24
24
  }
25
25
 
26
- cast(val, doc, init) {
26
+ cast(val, doc, init, prev, options) {
27
27
  if (val instanceof MongooseMap) {
28
28
  return val;
29
29
  }
30
30
 
31
- const path = this.path;
31
+ const path = options?.path ?? this.path;
32
32
 
33
33
  if (init) {
34
34
  const map = new MongooseMap({}, path, doc, this.$__schemaType);
@@ -5,6 +5,7 @@
5
5
  'use strict';
6
6
 
7
7
  const Binary = require('bson').Binary;
8
+ const UUID = require('bson').UUID;
8
9
  const utils = require('../utils');
9
10
 
10
11
  /**
@@ -207,6 +208,22 @@ MongooseBuffer.mixin.toBSON = function() {
207
208
  return new Binary(this, this._subtype || 0);
208
209
  };
209
210
 
211
+ /**
212
+ * Converts this buffer to a UUID. Throws an error if subtype is not 4.
213
+ *
214
+ * @return {UUID}
215
+ * @api public
216
+ * @method toUUID
217
+ * @memberOf MongooseBuffer
218
+ */
219
+
220
+ MongooseBuffer.mixin.toUUID = function() {
221
+ if (this._subtype !== 4) {
222
+ throw new Error('Cannot convert a Buffer with subtype ' + this._subtype + ' to a UUID');
223
+ }
224
+ return new UUID(this);
225
+ };
226
+
210
227
  /**
211
228
  * Determines if this buffer is equals to `other` buffer
212
229
  *
package/lib/types/map.js CHANGED
@@ -136,7 +136,7 @@ class MongooseMap extends Map {
136
136
  }
137
137
  } else {
138
138
  try {
139
- const options = this.$__schemaType.$isMongooseDocumentArray || this.$__schemaType.$isSingleNested ?
139
+ const options = this.$__schemaType.$isMongooseDocumentArray || this.$__schemaType.$isSingleNested || this.$__schemaType.$isMongooseArray || this.$__schemaType.$isSchemaMap ?
140
140
  { path: fullPath.call(this) } :
141
141
  null;
142
142
  value = this.$__schemaType.applySetters(
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mongoose",
3
3
  "description": "Mongoose MongoDB ODM",
4
- "version": "8.14.0",
4
+ "version": "8.14.1",
5
5
  "author": "Guillermo Rauch <guillermo@learnboost.com>",
6
6
  "keywords": [
7
7
  "mongodb",