Comparing version
@@ -86,2 +86,5 @@ /*! | ||
} | ||
if (query._mongooseOptions._asyncIterator) { | ||
this._mongooseOptions._asyncIterator = true; | ||
} | ||
@@ -383,25 +386,2 @@ if (model.collection._shouldBufferCommands() && model.collection.buffer) { | ||
/*! | ||
* ignore | ||
*/ | ||
QueryCursor.prototype.transformNull = function(val) { | ||
if (arguments.length === 0) { | ||
val = true; | ||
} | ||
this._mongooseOptions.transformNull = val; | ||
return this; | ||
}; | ||
/*! | ||
* ignore | ||
*/ | ||
QueryCursor.prototype._transformForAsyncIterator = function() { | ||
if (this._transforms.indexOf(_transformForAsyncIterator) === -1) { | ||
this.map(_transformForAsyncIterator); | ||
} | ||
return this; | ||
}; | ||
/** | ||
@@ -438,15 +418,9 @@ * Returns an asyncIterator for use with [`for/await/of` loops](https://thecodebarbarian.com/getting-started-with-async-iterators-in-node-js). | ||
if (Symbol.asyncIterator != null) { | ||
QueryCursor.prototype[Symbol.asyncIterator] = function() { | ||
return this.transformNull()._transformForAsyncIterator(); | ||
QueryCursor.prototype[Symbol.asyncIterator] = function queryCursorAsyncIterator() { | ||
// Set so QueryCursor knows it should transform results for async iterators into `{ value, done }` syntax | ||
this._mongooseOptions._asyncIterator = true; | ||
return this; | ||
}; | ||
} | ||
/*! | ||
* ignore | ||
*/ | ||
function _transformForAsyncIterator(doc) { | ||
return doc == null ? { done: true } : { value: doc, done: false }; | ||
} | ||
/** | ||
@@ -462,13 +436,35 @@ * Get the next doc from the underlying cursor and mongooseify it | ||
let callback = cb; | ||
if (ctx._transforms.length) { | ||
callback = function(err, doc) { | ||
if (err || (doc === null && !ctx._mongooseOptions.transformNull)) { | ||
return cb(err, doc); | ||
// Create a custom callback to handle transforms, async iterator, and transformNull | ||
callback = function(err, doc) { | ||
if (err) { | ||
return cb(err); | ||
} | ||
// Handle null documents - if asyncIterator, we need to return `done: true`, otherwise just | ||
// skip. In either case, avoid transforms. | ||
if (doc === null) { | ||
if (ctx._mongooseOptions._asyncIterator) { | ||
return cb(null, { done: true }); | ||
} else { | ||
return cb(null, null); | ||
} | ||
cb(err, ctx._transforms.reduce(function(doc, fn) { | ||
} | ||
// Apply transforms | ||
if (ctx._transforms.length && doc !== null) { | ||
doc = ctx._transforms.reduce(function(doc, fn) { | ||
return fn.call(ctx, doc); | ||
}, doc)); | ||
}; | ||
} | ||
}, doc); | ||
} | ||
// This option is set in `Symbol.asyncIterator` code paths. | ||
// For async iterator, we need to convert to {value, done} format | ||
if (ctx._mongooseOptions._asyncIterator) { | ||
return cb(null, { value: doc, done: false }); | ||
} | ||
return cb(null, doc); | ||
}; | ||
if (ctx._error) { | ||
@@ -475,0 +471,0 @@ return immediate(function() { |
{ | ||
"name": "mongoose", | ||
"description": "Mongoose MongoDB ODM", | ||
"version": "8.15.0", | ||
"version": "8.15.1", | ||
"author": "Guillermo Rauch <guillermo@learnboost.com>", | ||
@@ -6,0 +6,0 @@ "keywords": [ |
@@ -687,6 +687,12 @@ /// <reference path="./aggregate.d.ts" /> | ||
type _IDType = { _id?: boolean | 1 | 0 }; | ||
export type InclusionProjection<T> = IsItRecordAndNotAny<T> extends true ? Projector<WithLevel1NestedPaths<T>, true | 1> & _IDType : AnyObject; | ||
export type ExclusionProjection<T> = IsItRecordAndNotAny<T> extends true ? Projector<WithLevel1NestedPaths<T>, false | 0> & _IDType : AnyObject; | ||
export type InclusionProjection<T> = IsItRecordAndNotAny<T> extends true | ||
? Omit<Projector<WithLevel1NestedPaths<T>, true | 1>, '_id'> & _IDType | ||
: AnyObject; | ||
export type ExclusionProjection<T> = IsItRecordAndNotAny<T> extends true | ||
? Omit<Projector<WithLevel1NestedPaths<T>, false | 0>, '_id'> & _IDType | ||
: AnyObject; | ||
export type ProjectionType<T> = (InclusionProjection<T> & AnyObject) | (ExclusionProjection<T> & AnyObject) | string; | ||
export type ProjectionType<T> = (InclusionProjection<T> & AnyObject) | ||
| (ExclusionProjection<T> & AnyObject) | ||
| string; | ||
export type SortValues = SortOrder; | ||
@@ -693,0 +699,0 @@ |
@@ -322,6 +322,7 @@ declare module 'mongoose' { | ||
$vectorSearch: { | ||
exact?: boolean; | ||
index: string, | ||
path: string, | ||
queryVector: number[], | ||
numCandidates: number, | ||
numCandidates?: number, | ||
limit: number, | ||
@@ -328,0 +329,0 @@ filter?: Expression, |
Sorry, the diff of this file is too big to display
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
2892649
0.02%54530
0.01%