This commit is contained in:
2020-08-20 11:44:32 +02:00
parent 4715fc1814
commit 6aceefeb2f
2891 changed files with 11239 additions and 347539 deletions

78
node_modules/mongodb/lib/utils.js generated vendored
View File

@@ -1,6 +1,5 @@
'use strict';
const MongoError = require('./core/error').MongoError;
const ReadPreference = require('./core/topologies/read_preference');
const WriteConcern = require('./write_concern');
var shallowClone = function(obj) {
@@ -9,31 +8,6 @@ var shallowClone = function(obj) {
return copy;
};
// Figure out the read preference
var translateReadPreference = function(options) {
var r = null;
if (options.readPreference) {
r = options.readPreference;
} else {
return options;
}
if (typeof r === 'string') {
options.readPreference = new ReadPreference(r);
} else if (r && !(r instanceof ReadPreference) && typeof r === 'object') {
const mode = r.mode || r.preference;
if (mode && typeof mode === 'string') {
options.readPreference = new ReadPreference(mode, r.tags, {
maxStalenessSeconds: r.maxStalenessSeconds
});
}
} else if (!(r instanceof ReadPreference)) {
throw new TypeError('Invalid read preference: ' + r);
}
return options;
};
// Set simple property
var getSingleProperty = function(obj, name, value) {
Object.defineProperty(obj, name, {
@@ -490,37 +464,6 @@ function applyWriteConcern(target, sources, options) {
return target;
}
/**
* Resolves a read preference based on well-defined inheritance rules. This method will not only
* determine the read preference (if there is one), but will also ensure the returned value is a
* properly constructed instance of `ReadPreference`.
*
* @param {Collection|Db|MongoClient} parent The parent of the operation on which to determine the read
* preference, used for determining the inherited read preference.
* @param {Object} options The options passed into the method, potentially containing a read preference
* @returns {(ReadPreference|null)} The resolved read preference
*/
function resolveReadPreference(parent, options) {
options = options || {};
const session = options.session;
const inheritedReadPreference = parent.readPreference;
let readPreference;
if (options.readPreference) {
readPreference = ReadPreference.fromOptions(options);
} else if (session && session.inTransaction() && session.transaction.options.readPreference) {
// The transactions read preference MUST override all other user configurable read preferences.
readPreference = session.transaction.options.readPreference;
} else if (inheritedReadPreference != null) {
readPreference = inheritedReadPreference;
} else {
throw new Error('No readPreference was provided or inherited.');
}
return typeof readPreference === 'string' ? new ReadPreference(readPreference) : readPreference;
}
/**
* Checks if a given value is a Promise
*
@@ -778,6 +721,12 @@ function makeInterruptableAsyncInterval(fn, options) {
const timeUntilNextCall = Math.max(interval - timeSinceLastCall, 0);
lastWakeTime = currentTime;
// For the streaming protocol: there is nothing obviously stopping this
// interval from being woken up again while we are waiting "infinitely"
// for `fn` to be called again`. Since the function effectively
// never completes, the `timeUntilNextCall` will continue to grow
// negatively unbounded, so it will never trigger a reschedule here.
// debounce multiple calls to wake within the `minInterval`
if (timeSinceLastWake < minInterval) {
return;
@@ -810,6 +759,7 @@ function makeInterruptableAsyncInterval(fn, options) {
function executeAndReschedule() {
lastWakeTime = 0;
lastCallTime = now();
fn(err => {
if (err) throw err;
reschedule(interval);
@@ -826,6 +776,15 @@ function makeInterruptableAsyncInterval(fn, options) {
return { wake, stop };
}
function hasAtomicOperators(doc) {
if (Array.isArray(doc)) {
return doc.reduce((err, u) => err || hasAtomicOperators(u), null);
}
const keys = Object.keys(doc);
return keys.length > 0 && keys[0][0] === '$';
}
module.exports = {
filterOptions,
mergeOptions,
@@ -843,7 +802,6 @@ module.exports = {
debugOptions,
MAX_JS_INT: Number.MAX_SAFE_INTEGER + 1,
mergeOptionsAndWriteConcern,
translateReadPreference,
executeLegacyOperation,
applyRetryableWrites,
applyWriteConcern,
@@ -853,11 +811,11 @@ module.exports = {
deprecateOptions,
SUPPORTS,
MongoDBNamespace,
resolveReadPreference,
emitDeprecationWarning,
makeCounter,
maybePromise,
now,
calculateDurationInMs,
makeInterruptableAsyncInterval
makeInterruptableAsyncInterval,
hasAtomicOperators
};