Skip to content

Commit 0722e8f

Browse files
committed
Merge branch 'master' into 8.10
2 parents aeaa95c + 8cfc517 commit 0722e8f

16 files changed

+197
-97
lines changed

.github/workflows/benchmark.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
with:
2727
fetch-depth: 0
2828
- name: Setup node
29-
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
29+
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
3030
with:
3131
node-version: 22
3232

.github/workflows/documentation.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
3232

3333
- name: Setup node
34-
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
34+
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
3535
with:
3636
node-version: 22
3737

@@ -52,7 +52,7 @@ jobs:
5252
- run: git fetch --depth=1 --tags # download all tags for documentation
5353

5454
- name: Setup node
55-
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
55+
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
5656
with:
5757
node-version: 22
5858

.github/workflows/test.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
2626

2727
- name: Setup node
28-
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
28+
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
2929
with:
3030
node-version: 22
3131

@@ -61,7 +61,7 @@ jobs:
6161
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
6262

6363
- name: Setup node
64-
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
64+
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
6565
with:
6666
node-version: ${{ matrix.node }}
6767

@@ -96,7 +96,7 @@ jobs:
9696
steps:
9797
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
9898
- name: Setup node
99-
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
99+
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
100100
with:
101101
node-version: 22
102102
- name: Load MongoDB binary cache
@@ -124,7 +124,7 @@ jobs:
124124
steps:
125125
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
126126
- name: Setup node
127-
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
127+
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
128128
with:
129129
node-version: 22
130130
- run: npm install

.github/workflows/tidelift-alignment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- name: Checkout
1818
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
1919
- name: Setup node
20-
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
20+
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
2121
with:
2222
node-version: 22
2323
- name: Alignment

.github/workflows/tsd.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
2424

2525
- name: Setup node
26-
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
26+
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
2727
with:
2828
node-version: 22
2929

@@ -41,7 +41,7 @@ jobs:
4141
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
4242

4343
- name: Setup node
44-
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
44+
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
4545
with:
4646
node-version: 22
4747

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
8.9.6 / 2025-01-31
2+
==================
3+
* fix(document): allow setting values to undefined with set(obj) syntax with strict: false #15207 #15192
4+
* fix(schema): improve reason for UUID cast error, currently a TypeError #15215 #15202
5+
* fix(aggregate): improve error when calling near() with invalid coordinates #15206 #15188
6+
17
7.8.6 / 2025-01-20
28
===================
39
* chore: remove coverage output from bundle

lib/aggregate.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,11 +397,23 @@ Aggregate.prototype.project = function(arg) {
397397
* @memberOf Aggregate
398398
* @instance
399399
* @param {Object} arg
400+
* @param {Object|Array<Number>} arg.near GeoJSON point or coordinates array
400401
* @return {Aggregate}
401402
* @api public
402403
*/
403404

404405
Aggregate.prototype.near = function(arg) {
406+
if (arg == null) {
407+
throw new MongooseError('Aggregate `near()` must be called with non-nullish argument');
408+
}
409+
if (arg.near == null) {
410+
throw new MongooseError('Aggregate `near()` argument must have a `near` property');
411+
}
412+
const coordinates = Array.isArray(arg.near) ? arg.near : arg.near.coordinates;
413+
if (typeof arg.near === 'object' && (!Array.isArray(coordinates) || coordinates.length < 2 || coordinates.find(c => typeof c !== 'number'))) {
414+
throw new MongooseError(`Aggregate \`near()\` argument has invalid coordinates, got "${coordinates}"`);
415+
}
416+
405417
const op = {};
406418
op.$geoNear = arg;
407419
return this.append(op);

lib/cast/uuid.js

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
'use strict';
2+
3+
const MongooseBuffer = require('../types/buffer');
4+
5+
const UUID_FORMAT = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/i;
6+
const Binary = MongooseBuffer.Binary;
7+
8+
module.exports = function castUUID(value) {
9+
if (value == null) {
10+
return value;
11+
}
12+
13+
function newBuffer(initbuff) {
14+
const buff = new MongooseBuffer(initbuff);
15+
buff._subtype = 4;
16+
return buff;
17+
}
18+
19+
if (typeof value === 'string') {
20+
if (UUID_FORMAT.test(value)) {
21+
return stringToBinary(value);
22+
} else {
23+
throw new Error(`"${value}" is not a valid UUID string`);
24+
}
25+
}
26+
27+
if (Buffer.isBuffer(value)) {
28+
return newBuffer(value);
29+
}
30+
31+
if (value instanceof Binary) {
32+
return newBuffer(value.value(true));
33+
}
34+
35+
// Re: gh-647 and gh-3030, we're ok with casting using `toString()`
36+
// **unless** its the default Object.toString, because "[object Object]"
37+
// doesn't really qualify as useful data
38+
if (value.toString && value.toString !== Object.prototype.toString) {
39+
if (UUID_FORMAT.test(value.toString())) {
40+
return stringToBinary(value.toString());
41+
}
42+
}
43+
44+
throw new Error(`"${value}" cannot be casted to a UUID`);
45+
};
46+
47+
module.exports.UUID_FORMAT = UUID_FORMAT;
48+
49+
/**
50+
* Helper function to convert the input hex-string to a buffer
51+
* @param {String} hex The hex string to convert
52+
* @returns {Buffer} The hex as buffer
53+
* @api private
54+
*/
55+
56+
function hex2buffer(hex) {
57+
// use buffer built-in function to convert from hex-string to buffer
58+
const buff = hex != null && Buffer.from(hex, 'hex');
59+
return buff;
60+
}
61+
62+
/**
63+
* Convert a String to Binary
64+
* @param {String} uuidStr The value to process
65+
* @returns {MongooseBuffer} The binary to store
66+
* @api private
67+
*/
68+
69+
function stringToBinary(uuidStr) {
70+
// Protect against undefined & throwing err
71+
if (typeof uuidStr !== 'string') uuidStr = '';
72+
const hex = uuidStr.replace(/[{}-]/g, ''); // remove extra characters
73+
const bytes = hex2buffer(hex);
74+
const buff = new MongooseBuffer(bytes);
75+
buff._subtype = 4;
76+
77+
return buff;
78+
}

lib/document.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1147,7 +1147,7 @@ Document.prototype.$set = function $set(path, val, type, options) {
11471147
} else if (pathtype === 'nested' && valForKey == null) {
11481148
this.$set(pathName, valForKey, constructing, options);
11491149
}
1150-
} else if (valForKey !== void 0) {
1150+
} else {
11511151
this.$set(pathName, valForKey, constructing, options);
11521152
}
11531153
}

lib/helpers/document/applyDefaults.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ module.exports = function applyDefaults(doc, fields, exclude, hasIncludedChildre
1919
const type = doc.$__schema.paths[p];
2020
const path = type.splitPath();
2121
const len = path.length;
22+
if (path[len - 1] === '$*') {
23+
continue;
24+
}
2225
let included = false;
2326
let doc_ = doc._doc;
2427
for (let j = 0; j < len; ++j) {

lib/schema/uuid.js

Lines changed: 3 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -7,44 +7,14 @@
77
const MongooseBuffer = require('../types/buffer');
88
const SchemaType = require('../schemaType');
99
const CastError = SchemaType.CastError;
10+
const castUUID = require('../cast/uuid');
1011
const createJSONSchemaTypeDefinition = require('../helpers/createJSONSchemaTypeDefinition');
1112
const utils = require('../utils');
1213
const handleBitwiseOperator = require('./operators/bitwise');
1314

14-
const UUID_FORMAT = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/i;
15+
const UUID_FORMAT = castUUID.UUID_FORMAT;
1516
const Binary = MongooseBuffer.Binary;
1617

17-
/**
18-
* Helper function to convert the input hex-string to a buffer
19-
* @param {String} hex The hex string to convert
20-
* @returns {Buffer} The hex as buffer
21-
* @api private
22-
*/
23-
24-
function hex2buffer(hex) {
25-
// use buffer built-in function to convert from hex-string to buffer
26-
const buff = hex != null && Buffer.from(hex, 'hex');
27-
return buff;
28-
}
29-
30-
/**
31-
* Convert a String to Binary
32-
* @param {String} uuidStr The value to process
33-
* @returns {MongooseBuffer} The binary to store
34-
* @api private
35-
*/
36-
37-
function stringToBinary(uuidStr) {
38-
// Protect against undefined & throwing err
39-
if (typeof uuidStr !== 'string') uuidStr = '';
40-
const hex = uuidStr.replace(/[{}-]/g, ''); // remove extra characters
41-
const bytes = hex2buffer(hex);
42-
const buff = new MongooseBuffer(bytes);
43-
buff._subtype = 4;
44-
45-
return buff;
46-
}
47-
4818
/**
4919
* Convert binary to a uuid string
5020
* @param {Buffer|Binary|String} uuidBin The value to process
@@ -110,44 +80,7 @@ SchemaUUID.prototype.constructor = SchemaUUID;
11080
* ignore
11181
*/
11282

113-
SchemaUUID._cast = function(value) {
114-
if (value == null) {
115-
return value;
116-
}
117-
118-
function newBuffer(initbuff) {
119-
const buff = new MongooseBuffer(initbuff);
120-
buff._subtype = 4;
121-
return buff;
122-
}
123-
124-
if (typeof value === 'string') {
125-
if (UUID_FORMAT.test(value)) {
126-
return stringToBinary(value);
127-
} else {
128-
throw new CastError(SchemaUUID.schemaName, value, this.path);
129-
}
130-
}
131-
132-
if (Buffer.isBuffer(value)) {
133-
return newBuffer(value);
134-
}
135-
136-
if (value instanceof Binary) {
137-
return newBuffer(value.value(true));
138-
}
139-
140-
// Re: gh-647 and gh-3030, we're ok with casting using `toString()`
141-
// **unless** its the default Object.toString, because "[object Object]"
142-
// doesn't really qualify as useful data
143-
if (value.toString && value.toString !== Object.prototype.toString) {
144-
if (UUID_FORMAT.test(value.toString())) {
145-
return stringToBinary(value.toString());
146-
}
147-
}
148-
149-
throw new CastError(SchemaUUID.schemaName, value, this.path);
150-
};
83+
SchemaUUID._cast = castUUID;
15184

15285
/**
15386
* Attaches a getter for all UUID instances.

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "mongoose",
33
"description": "Mongoose MongoDB ODM",
4-
"version": "8.9.5",
4+
"version": "8.9.6",
55
"author": "Guillermo Rauch <guillermo@learnboost.com>",
66
"keywords": [
77
"mongodb",
@@ -29,8 +29,8 @@
2929
"sift": "17.1.3"
3030
},
3131
"devDependencies": {
32-
"@babel/core": "7.26.0",
33-
"@babel/preset-env": "7.26.0",
32+
"@babel/core": "7.26.7",
33+
"@babel/preset-env": "7.26.7",
3434
"@typescript-eslint/eslint-plugin": "^8.19.1",
3535
"@typescript-eslint/parser": "^8.19.1",
3636
"acquit": "1.3.0",
@@ -48,14 +48,14 @@
4848
"eslint-plugin-markdown": "^5.1.0",
4949
"eslint-plugin-mocha-no-only": "1.2.0",
5050
"express": "^4.19.2",
51-
"fs-extra": "~11.2.0",
51+
"fs-extra": "~11.3.0",
5252
"highlight.js": "11.11.1",
5353
"lodash.isequal": "4.5.0",
5454
"lodash.isequalwith": "4.4.0",
5555
"markdownlint-cli2": "^0.17.1",
56-
"marked": "15.0.4",
56+
"marked": "15.0.6",
5757
"mkdirp": "^3.0.1",
58-
"mocha": "11.0.1",
58+
"mocha": "11.1.0",
5959
"moment": "2.30.1",
6060
"mongodb-memory-server": "10.1.3",
6161
"ncp": "^2.0.0",
@@ -65,8 +65,8 @@
6565
"sinon": "19.0.2",
6666
"stream-browserify": "3.0.0",
6767
"tsd": "0.31.2",
68-
"typescript": "5.7.2",
69-
"uuid": "11.0.3",
68+
"typescript": "5.7.3",
69+
"uuid": "11.0.5",
7070
"webpack": "5.97.1"
7171
},
7272
"directories": {

0 commit comments

Comments
 (0)