Page MenuHomeSealhub

bin_node_modules_mongodb_lib_mongodb_utils.js.html
No OneTemporary

Authored By
Unknown
Size
21 KB
Referenced Files
None
Subscribers
None

bin_node_modules_mongodb_lib_mongodb_utils.js.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>bin/node_modules/mongodb/lib/mongodb/utils.js - Prometheus Framework</title>
<link rel="stylesheet" href="http://yui.yahooapis.com/3.9.1/build/cssgrids/cssgrids-min.css">
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
<link rel="stylesheet" href="../assets/css/main.css" id="site_styles">
<link rel="shortcut icon" type="image/png" href="../assets/favicon.png">
<script src="http://yui.yahooapis.com/combo?3.9.1/build/yui/yui-min.js"></script>
</head>
<body class="yui3-skin-sam">
<div id="doc">
<div id="hd" class="yui3-g header">
<div class="yui3-u-3-4">
<h1><img src="../assets/css/logo.png" title="Prometheus Framework"></h1>
</div>
<div class="yui3-u-1-4 version">
<em>API Docs for: 0.1</em>
</div>
</div>
<div id="bd" class="yui3-g">
<div class="yui3-u-1-4">
<div id="docs-sidebar" class="sidebar apidocs">
<div id="api-list">
<h2 class="off-left">APIs</h2>
<div id="api-tabview" class="tabview">
<ul class="tabs">
<li><a href="#api-classes">Classes</a></li>
<li><a href="#api-modules">Modules</a></li>
</ul>
<div id="api-tabview-filter">
<input type="search" id="api-filter" placeholder="Type to filter APIs">
</div>
<div id="api-tabview-panel">
<ul id="api-classes" class="apis classes">
<li><a href="../classes/Represents a
Replicaset Configuration.html">Represents a
Replicaset Configuration</a></li>
<li><a href="../classes/Represents a BatchWriteResult.html">Represents a BatchWriteResult</a></li>
<li><a href="../classes/Represents a Collection.html">Represents a Collection</a></li>
<li><a href="../classes/Represents a Cursor..html">Represents a Cursor.</a></li>
<li><a href="../classes/Represents a CursorStream..html">Represents a CursorStream.</a></li>
<li><a href="../classes/Represents a Db.html">Represents a Db</a></li>
<li><a href="../classes/Represents a GridFS File Stream..html">Represents a GridFS File Stream.</a></li>
<li><a href="../classes/.html"></a></li>
<li><a href="../classes/Represents a MongoClient.html">Represents a MongoClient</a></li>
<li><a href="../classes/Represents a Mongos connection with failover to backup proxies.html">Represents a Mongos connection with failover to backup proxies</a></li>
<li><a href="../classes/Represents a OrderedBulkOperation.html">Represents a OrderedBulkOperation</a></li>
<li><a href="../classes/Represents a Read Preference..html">Represents a Read Preference.</a></li>
<li><a href="../classes/Represents a Server connection..html">Represents a Server connection.</a></li>
<li><a href="../classes/Represents a UnorderedBulkOperation.html">Represents a UnorderedBulkOperation</a></li>
<li><a href="../classes/Represents the Admin methods of MongoDB..html">Represents the Admin methods of MongoDB.</a></li>
<li><a href="../classes/Represents the Grid..html">Represents the Grid.</a></li>
<li><a href="../classes/Represents the GridStore..html">Represents the GridStore.</a></li>
</ul>
<ul id="api-modules" class="apis modules">
<li><a href="../modules/association.html">association</a></li>
<li><a href="../modules/database-accessor.html">database-accessor</a></li>
<li><a href="../modules/field-type-manager.html">field-type-manager</a></li>
<li><a href="../modules/resource-type-manager.html">resource-type-manager</a></li>
</ul>
</div>
</div>
</div>
</div>
</div>
<div class="yui3-u-3-4">
<div id="api-options">
Show:
<label for="api-show-inherited">
<input type="checkbox" id="api-show-inherited" checked>
Inherited
</label>
<label for="api-show-protected">
<input type="checkbox" id="api-show-protected">
Protected
</label>
<label for="api-show-private">
<input type="checkbox" id="api-show-private">
Private
</label>
<label for="api-show-deprecated">
<input type="checkbox" id="api-show-deprecated">
Deprecated
</label>
</div>
<div class="apidocs">
<div id="docs-main">
<div class="content">
<h1 class="file-heading">File: bin/node_modules/mongodb/lib/mongodb/utils.js</h1>
<div class="file">
<pre class="code prettyprint linenums">
var timers = require(&#x27;timers&#x27;);
/**
* Sort functions, Normalize and prepare sort parameters
*/
var formatSortValue = exports.formatSortValue = function(sortDirection) {
var value = (&quot;&quot; + sortDirection).toLowerCase();
switch (value) {
case &#x27;ascending&#x27;:
case &#x27;asc&#x27;:
case &#x27;1&#x27;:
return 1;
case &#x27;descending&#x27;:
case &#x27;desc&#x27;:
case &#x27;-1&#x27;:
return -1;
default:
throw new Error(&quot;Illegal sort clause, must be of the form &quot;
+ &quot;[[&#x27;field1&#x27;, &#x27;(ascending|descending)&#x27;], &quot;
+ &quot;[&#x27;field2&#x27;, &#x27;(ascending|descending)&#x27;]]&quot;);
}
};
var formattedOrderClause = exports.formattedOrderClause = function(sortValue) {
var orderBy = {};
if(sortValue == null) return null;
if (Array.isArray(sortValue)) {
if(sortValue.length === 0) {
return null;
}
for(var i = 0; i &lt; sortValue.length; i++) {
if(sortValue[i].constructor == String) {
orderBy[sortValue[i]] = 1;
} else {
orderBy[sortValue[i][0]] = formatSortValue(sortValue[i][1]);
}
}
} else if(sortValue != null &amp;&amp; typeof sortValue == &#x27;object&#x27;) {
orderBy = sortValue;
} else if (typeof sortValue == &#x27;string&#x27;) {
orderBy[sortValue] = 1;
} else {
throw new Error(&quot;Illegal sort clause, must be of the form &quot; +
&quot;[[&#x27;field1&#x27;, &#x27;(ascending|descending)&#x27;], [&#x27;field2&#x27;, &#x27;(ascending|descending)&#x27;]]&quot;);
}
return orderBy;
};
exports.encodeInt = function(value) {
var buffer = new Buffer(4);
buffer[3] = (value &gt;&gt; 24) &amp; 0xff;
buffer[2] = (value &gt;&gt; 16) &amp; 0xff;
buffer[1] = (value &gt;&gt; 8) &amp; 0xff;
buffer[0] = value &amp; 0xff;
return buffer;
}
exports.encodeIntInPlace = function(value, buffer, index) {
buffer[index + 3] = (value &gt;&gt; 24) &amp; 0xff;
buffer[index + 2] = (value &gt;&gt; 16) &amp; 0xff;
buffer[index + 1] = (value &gt;&gt; 8) &amp; 0xff;
buffer[index] = value &amp; 0xff;
}
exports.encodeCString = function(string) {
var buf = new Buffer(string, &#x27;utf8&#x27;);
return [buf, new Buffer([0])];
}
exports.decodeUInt32 = function(array, index) {
return array[index] | array[index + 1] &lt;&lt; 8 | array[index + 2] &lt;&lt; 16 | array[index + 3] &lt;&lt; 24;
}
// Decode the int
exports.decodeUInt8 = function(array, index) {
return array[index];
}
/**
* Context insensitive type checks
*/
var toString = Object.prototype.toString;
var isObject = exports.isObject = function (arg) {
return &#x27;[object Object]&#x27; == toString.call(arg)
}
exports.isArray = function (arg) {
return Array.isArray(arg) ||
&#x27;object&#x27; == typeof arg &amp;&amp; &#x27;[object Array]&#x27; == toString.call(arg)
}
exports.isDate = function (arg) {
return &#x27;object&#x27; == typeof arg &amp;&amp; &#x27;[object Date]&#x27; == toString.call(arg)
}
exports.isRegExp = function (arg) {
return &#x27;object&#x27; == typeof arg &amp;&amp; &#x27;[object RegExp]&#x27; == toString.call(arg)
}
/**
* Wrap a Mongo error document in an Error instance
* @ignore
* @api private
*/
var toError = function(error) {
if (error instanceof Error) return error;
var msg = error.err || error.errmsg || error.errMessage || error;
var e = new Error(msg);
e.name = &#x27;MongoError&#x27;;
// Get all object keys
var keys = typeof error == &#x27;object&#x27;
? Object.keys(error)
: [];
for(var i = 0; i &lt; keys.length; i++) {
e[keys[i]] = error[keys[i]];
}
return e;
}
exports.toError = toError;
/**
* Convert a single level object to an array
* @ignore
* @api private
*/
exports.objectToArray = function(object) {
var list = [];
for(var name in object) {
list.push(object[name])
}
return list;
}
/**
* Handle single command document return
* @ignore
* @api private
*/
exports.handleSingleCommandResultReturn = function(override_value_true, override_value_false, callback) {
return function(err, result, connection) {
if(callback == null) return;
if(err &amp;&amp; typeof callback == &#x27;function&#x27;) return callback(err, null);
if(!result || !result.documents || result.documents.length == 0)
if(typeof callback == &#x27;function&#x27;) return callback(toError(&quot;command failed to return results&quot;), null)
if(result &amp;&amp; result.documents[0].ok == 1) {
if(override_value_true) return callback(null, override_value_true)
if(typeof callback == &#x27;function&#x27;) return callback(null, result.documents[0]);
}
// Return the error from the document
if(typeof callback == &#x27;function&#x27;) return callback(toError(result.documents[0]), override_value_false);
}
}
/**
* Return correct processor
* @ignore
* @api private
*/
exports.processor = function() {
// Set processor, setImmediate if 0.10 otherwise nextTick
process.maxTickDepth = Infinity;
// Only use nextTick
return process.nextTick;
}
/**
* Allow setting the socketTimeoutMS on all connections
* to work around issues such as secondaries blocking due to compaction
*
* @ignore
* @api private
*/
exports.setSocketTimeoutProperty = function(self, options) {
Object.defineProperty(self, &quot;socketTimeoutMS&quot;, {
enumerable: true
, get: function () { return options.socketTimeoutMS; }
, set: function (value) {
// Set the socket timeoutMS value
options.socketTimeoutMS = value;
// Get all the connections
var connections = self.allRawConnections();
for(var i = 0; i &lt; connections.length; i++) {
connections[i].socketTimeoutMS = value;
}
}
});
}
/**
* Determine if the server supports write commands
*
* @ignore
* @api private
*/
exports.hasWriteCommands = function(connection) {
return connection != null &amp;&amp; connection.serverCapabilities != null &amp;&amp; connection.serverCapabilities.hasWriteCommands;
}
/**
* Fetch server capabilities
*
* @ignore
* @api private
*/
exports.serverCapabilities = function(connection) {
return connection != null &amp;&amp; connection.serverCapabilities != null &amp;&amp; connection.serverCapabilities.hasWriteCommands;
}
/**
* Create index name based on field spec
*
* @ignore
* @api private
*/
exports.parseIndexOptions = function(fieldOrSpec) {
var fieldHash = {};
var indexes = [];
var keys;
// Get all the fields accordingly
if(&#x27;string&#x27; == typeof fieldOrSpec) {
// &#x27;type&#x27;
indexes.push(fieldOrSpec + &#x27;_&#x27; + 1);
fieldHash[fieldOrSpec] = 1;
} else if(Array.isArray(fieldOrSpec)) {
fieldOrSpec.forEach(function(f) {
if(&#x27;string&#x27; == typeof f) {
// [{location:&#x27;2d&#x27;}, &#x27;type&#x27;]
indexes.push(f + &#x27;_&#x27; + 1);
fieldHash[f] = 1;
} else if(Array.isArray(f)) {
// [[&#x27;location&#x27;, &#x27;2d&#x27;],[&#x27;type&#x27;, 1]]
indexes.push(f[0] + &#x27;_&#x27; + (f[1] || 1));
fieldHash[f[0]] = f[1] || 1;
} else if(isObject(f)) {
// [{location:&#x27;2d&#x27;}, {type:1}]
keys = Object.keys(f);
keys.forEach(function(k) {
indexes.push(k + &#x27;_&#x27; + f[k]);
fieldHash[k] = f[k];
});
} else {
// undefined (ignore)
}
});
} else if(isObject(fieldOrSpec)) {
// {location:&#x27;2d&#x27;, type:1}
keys = Object.keys(fieldOrSpec);
keys.forEach(function(key) {
indexes.push(key + &#x27;_&#x27; + fieldOrSpec[key]);
fieldHash[key] = fieldOrSpec[key];
});
}
return {
name: indexes.join(&quot;_&quot;), keys: keys, fieldHash: fieldHash
}
}
exports.decorateCommand = function(command, options, exclude) {
for(var name in options) {
if(exclude[name] == null) command[name] = options[name];
}
return command;
}
exports.shallowObjectCopy = function(object) {
var c = {};
for(var n in object) c[n] = object[n];
return c;
}
</pre>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="../assets/vendor/prettify/prettify-min.js"></script>
<script>prettyPrint();</script>
<script src="../assets/js/yui-prettify.js"></script>
<script src="../assets/../api.js"></script>
<script src="../assets/js/api-filter.js"></script>
<script src="../assets/js/api-list.js"></script>
<script src="../assets/js/api-search.js"></script>
<script src="../assets/js/apidocs.js"></script>
</body>
</html>

File Metadata

Mime Type
text/html
Expires
Fri, Nov 27, 16:15 (1 d, 17 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1220288
Default Alt Text
bin_node_modules_mongodb_lib_mongodb_utils.js.html (21 KB)

Event Timeline