documentdb
Advanced tools
Comparing version 1.0.2 to 1.0.3
## Changes in 1.0.2 : ## | ||
- Resolved issue [#45](https://github.com/Azure/azure-documentdb-node/issues/45) - promises wrapper does not include header with error. | ||
- Resolved issue [#45](https://github.com/Azure/azure-documentdb-node/issues/45) - promises wrapper does not include header with error. | ||
## Changes in 1.0.1 : ## | ||
- Implemented ability to query for conflicts by adding readConflicts, readConflictAsync, queryConflicts; | ||
- Updated API documentation | ||
- Resolved issue [#41](https://github.com/Azure/azure-documentdb-node/issues/41) - client.createDocumentAsync error |
@@ -5,3 +5,3 @@ //---------------------------------------------------------------------------- | ||
'use strict'; | ||
"use strict"; | ||
@@ -11,6 +11,6 @@ var crypto = require("crypto"); | ||
var AuthHandler = { | ||
getAuthorizationHeader: function(documentClient, verb, path, resourceId, resourceType, headers) { | ||
getAuthorizationHeader: function (documentClient, verb, path, resourceId, resourceType, headers) { | ||
if (documentClient.masterKey) { | ||
return this.getAuthorizationTokenUsingMasterKey(verb, resourceId, resourceType, headers, documentClient.masterKey); | ||
} else if(documentClient.resourceTokens) { | ||
} else if (documentClient.resourceTokens) { | ||
return this.getAuthorizationTokenUsingResourceTokens(documentClient.resourceTokens, path, resourceId); | ||
@@ -20,3 +20,3 @@ } | ||
getAuthorizationTokenUsingMasterKey: function(verb, resourceId, resourceType, headers, masterKey){ | ||
getAuthorizationTokenUsingMasterKey: function (verb, resourceId, resourceType, headers, masterKey) { | ||
var key = new Buffer(masterKey, "base64"); | ||
@@ -35,9 +35,9 @@ | ||
var MasterToken = "master"; | ||
var TokenVersion = "1.0"; | ||
return "type=" + MasterToken +"&ver=" + TokenVersion + "&sig=" + signature; | ||
return "type=" + MasterToken + "&ver=" + TokenVersion + "&sig=" + signature; | ||
}, | ||
getAuthorizationTokenUsingResourceTokens: function(resourceTokens, path, resourceId){ | ||
getAuthorizationTokenUsingResourceTokens: function (resourceTokens, path, resourceId) { | ||
if (resourceTokens[resourceId]) { | ||
@@ -48,3 +48,3 @@ return resourceTokens[resourceId]; | ||
var resourceTypes = ["dbs", "colls", "docs", "sprocs", "udfs", "triggers", "users", "permissions", "attachments", "media", "conflicts", "offers"]; | ||
for (var i = pathParts.length - 1; i >= 0;i--) { | ||
for (var i = pathParts.length - 1; i >= 0; i--) { | ||
if (resourceTypes.indexOf(pathParts[i]) === -1) { | ||
@@ -58,3 +58,3 @@ if (resourceTokens[pathParts[i]]) { | ||
} | ||
} | ||
}; | ||
@@ -61,0 +61,0 @@ if (typeof exports !== "undefined") { |
352
lib/base.js
@@ -5,89 +5,113 @@ //---------------------------------------------------------------------------- | ||
'use strict'; | ||
"use strict"; | ||
var AuthHandler = require("./auth"); | ||
var Constants = require("./constants"); | ||
//SCRIPT START | ||
function initializeProperties(target, members, prefix) { | ||
var keys = Object.keys(members); | ||
var properties; | ||
var i, len; | ||
for (i = 0, len = keys.length; i < len; i++) { | ||
var key = keys[i]; | ||
var enumerable = key.charCodeAt(0) !== /*_*/95; | ||
var member = members[key]; | ||
if (member && typeof member === "object") { | ||
if (member.value !== undefined || typeof member.get === "function" || typeof member.set === "function") { | ||
if (member.enumerable === undefined) { | ||
member.enumerable = enumerable; | ||
} | ||
if (prefix && member.setName && typeof member.setName === "function") { | ||
member.setName(prefix + "." + key) | ||
} | ||
properties = properties || {}; | ||
properties[key] = member; | ||
continue; | ||
function initializeProperties(target, members, prefix) { | ||
var keys = Object.keys(members); | ||
var properties; | ||
var i, len; | ||
for (i = 0, len = keys.length; i < len; i++) { | ||
var key = keys[i]; | ||
var enumerable = key.charCodeAt(0) !== /*_*/95; | ||
var member = members[key]; | ||
if (member && typeof member === "object") { | ||
if (member.value !== undefined || typeof member.get === "function" || typeof member.set === "function") { | ||
if (member.enumerable === undefined) { | ||
member.enumerable = enumerable; | ||
} | ||
} | ||
if (!enumerable) { | ||
if (prefix && member.setName && typeof member.setName === "function") { | ||
member.setName(prefix + "." + key); | ||
} | ||
properties = properties || {}; | ||
properties[key] = { value: member, enumerable: enumerable, configurable: true, writable: true } | ||
properties[key] = member; | ||
continue; | ||
} | ||
target[key] = member; | ||
} | ||
if (properties) { | ||
Object.defineProperties(target, properties); | ||
if (!enumerable) { | ||
properties = properties || {}; | ||
properties[key] = { value: member, enumerable: enumerable, configurable: true, writable: true }; | ||
continue; | ||
} | ||
target[key] = member; | ||
} | ||
if (properties) { | ||
Object.defineProperties(target, properties); | ||
} | ||
} | ||
/** | ||
* Defines a new namespace with the specified name under the specified parent namespace. | ||
* @param {Object} parentNamespace - The parent namespace. | ||
* @param {String} name - The name of the new namespace. | ||
* @param {Object} members - The members of the new namespace. | ||
* @returns {Function} - The newly-defined namespace. | ||
*/ | ||
function defineWithParent(parentNamespace, name, members) { | ||
var currentNamespace = parentNamespace || {}; | ||
/** | ||
* Defines a new namespace with the specified name under the specified parent namespace. | ||
* @param {Object} parentNamespace - The parent namespace. | ||
* @param {String} name - The name of the new namespace. | ||
* @param {Object} members - The members of the new namespace. | ||
* @returns {Function} - The newly-defined namespace. | ||
*/ | ||
function defineWithParent(parentNamespace, name, members) { | ||
var currentNamespace = parentNamespace || {}; | ||
if (name) { | ||
var namespaceFragments = name.split("."); | ||
for (var i = 0, len = namespaceFragments.length; i < len; i++) { | ||
var namespaceName = namespaceFragments[i]; | ||
if (!currentNamespace[namespaceName]) { | ||
Object.defineProperty(currentNamespace, namespaceName, | ||
{ value: {}, writable: false, enumerable: true, configurable: true } | ||
); | ||
} | ||
currentNamespace = currentNamespace[namespaceName]; | ||
if (name) { | ||
var namespaceFragments = name.split("."); | ||
for (var i = 0, len = namespaceFragments.length; i < len; i++) { | ||
var namespaceName = namespaceFragments[i]; | ||
if (!currentNamespace[namespaceName]) { | ||
Object.defineProperty(currentNamespace, namespaceName, | ||
{ value: {}, writable: false, enumerable: true, configurable: true } | ||
); | ||
} | ||
currentNamespace = currentNamespace[namespaceName]; | ||
} | ||
} | ||
if (members) { | ||
initializeProperties(currentNamespace, members, name || "<ANONYMOUS>"); | ||
} | ||
return currentNamespace; | ||
if (members) { | ||
initializeProperties(currentNamespace, members, name || "<ANONYMOUS>"); | ||
} | ||
/** | ||
* Defines a new namespace with the specified name. | ||
* @param {String} name - The name of the namespace. This could be a dot-separated name for nested namespaces. | ||
* @param {Object} members - The members of the new namespace. | ||
* @returns {Function} - The newly-defined namespace. | ||
*/ | ||
function define(name, members) { | ||
return defineWithParent(undefined, name, members); | ||
return currentNamespace; | ||
} | ||
/** | ||
* Defines a new namespace with the specified name. | ||
* @param {String} name - The name of the namespace. This could be a dot-separated name for nested namespaces. | ||
* @param {Object} members - The members of the new namespace. | ||
* @returns {Function} - The newly-defined namespace. | ||
*/ | ||
function define(name, members) { | ||
return defineWithParent(undefined, name, members); | ||
} | ||
/** | ||
* Defines a class using the given constructor and the specified instance members. | ||
* @param {Function} constructor - A constructor function that is used to instantiate this class. | ||
* @param {Object} instanceMembers - The set of instance fields, properties, and methods to be made available on the class. | ||
* @param {Object} staticMembers - The set of static fields, properties, and methods to be made available on the class. | ||
* @returns {Function} - The newly-defined class. | ||
*/ | ||
function defineClass(constructor, instanceMembers, staticMembers) { | ||
constructor = constructor || function () { }; | ||
if (instanceMembers) { | ||
initializeProperties(constructor.prototype, instanceMembers); | ||
} | ||
if (staticMembers) { | ||
initializeProperties(constructor, staticMembers); | ||
} | ||
return constructor; | ||
} | ||
/** | ||
* Defines a class using the given constructor and the specified instance members. | ||
* @param {Function} constructor - A constructor function that is used to instantiate this class. | ||
* @param {Object} instanceMembers - The set of instance fields, properties, and methods to be made available on the class. | ||
* @param {Object} staticMembers - The set of static fields, properties, and methods to be made available on the class. | ||
* @returns {Function} - The newly-defined class. | ||
*/ | ||
function defineClass(constructor, instanceMembers, staticMembers) { | ||
/** | ||
* Creates a sub-class based on the supplied baseClass parameter, using prototypal inheritance. | ||
* @param {Function} baseClass - The class to inherit from. | ||
* @param {Function} constructor - A constructor function that is used to instantiate this class. | ||
* @param {Object} instanceMembers - The set of instance fields, properties, and methods to be made available on the class. | ||
* @param {Object} staticMembers - The set of static fields, properties, and methods to be made available on the class. | ||
* @returns {Function} - The newly-defined class. | ||
*/ | ||
function derive(baseClass, constructor, instanceMembers, staticMembers) { | ||
if (baseClass) { | ||
constructor = constructor || function () { }; | ||
var basePrototype = baseClass.prototype; | ||
constructor.prototype = Object.create(basePrototype); | ||
Object.defineProperty(constructor.prototype, "constructor", { value: constructor, writable: true, configurable: true, enumerable: true }); | ||
if (instanceMembers) { | ||
@@ -100,56 +124,33 @@ initializeProperties(constructor.prototype, instanceMembers); | ||
return constructor; | ||
} else { | ||
return defineClass(constructor, instanceMembers, staticMembers); | ||
} | ||
} | ||
/** | ||
* Creates a sub-class based on the supplied baseClass parameter, using prototypal inheritance. | ||
* @param {Function} baseClass - The class to inherit from. | ||
* @param {Function} constructor - A constructor function that is used to instantiate this class. | ||
* @param {Object} instanceMembers - The set of instance fields, properties, and methods to be made available on the class. | ||
* @param {Object} staticMembers - The set of static fields, properties, and methods to be made available on the class. | ||
* @returns {Function} - The newly-defined class. | ||
*/ | ||
function derive(baseClass, constructor, instanceMembers, staticMembers) { | ||
if (baseClass) { | ||
constructor = constructor || function () { }; | ||
var basePrototype = baseClass.prototype; | ||
constructor.prototype = Object.create(basePrototype); | ||
Object.defineProperty(constructor.prototype, "constructor", { value: constructor, writable: true, configurable: true, enumerable: true }); | ||
if (instanceMembers) { | ||
initializeProperties(constructor.prototype, instanceMembers); | ||
} | ||
if (staticMembers) { | ||
initializeProperties(constructor, staticMembers); | ||
} | ||
return constructor; | ||
} else { | ||
return defineClass(constructor, instanceMembers, staticMembers); | ||
} | ||
/** | ||
* Defines a class using the given constructor and the union of the set of instance members | ||
* specified by all the mixin objects. The mixin parameter list is of variable length. | ||
* @param {object} constructor - A constructor function that is used to instantiate this class. | ||
* @returns {Function} - The newly-defined class. | ||
*/ | ||
function mix(constructor) { | ||
constructor = constructor || function () { }; | ||
var i, len; | ||
for (i = 1, len = arguments.length; i < len; i++) { | ||
initializeProperties(constructor.prototype, arguments[i]); | ||
} | ||
return constructor; | ||
} | ||
/** | ||
* Defines a class using the given constructor and the union of the set of instance members | ||
* specified by all the mixin objects. The mixin parameter list is of variable length. | ||
* @param {object} constructor - A constructor function that is used to instantiate this class. | ||
* @returns {Function} - The newly-defined class. | ||
*/ | ||
function mix(constructor) { | ||
constructor = constructor || function () { }; | ||
var i, len; | ||
for (i = 1, len = arguments.length; i < len; i++) { | ||
initializeProperties(constructor.prototype, arguments[i]); | ||
} | ||
return constructor; | ||
} | ||
var Base = { | ||
NotImplementedException: "NotImplementedException", | ||
defineWithParent : defineWithParent, | ||
define : define, | ||
defineWithParent: defineWithParent, | ||
define: define, | ||
defineClass: defineClass, | ||
derive: derive, | ||
mix: mix, | ||
@@ -159,5 +160,5 @@ | ||
for (var property in extent) { | ||
if (typeof(extent[property]) !== "function") { | ||
if (typeof extent[property] !== "function") { | ||
obj[property] = extent[property]; | ||
} | ||
} | ||
} | ||
@@ -172,3 +173,3 @@ return obj; | ||
} | ||
return result; | ||
@@ -181,3 +182,3 @@ }, | ||
options = options || {}; | ||
if (options.continuation) { | ||
@@ -188,7 +189,7 @@ headers[Constants.HttpHeaders.Continuation] = options.continuation; | ||
if (options.preTriggerInclude) { | ||
headers[Constants.HttpHeaders.PreTriggerInclude] = options.preTriggerInclude.constructor === Array? options.preTriggerInclude.join(","): options.preTriggerInclude; | ||
headers[Constants.HttpHeaders.PreTriggerInclude] = options.preTriggerInclude.constructor === Array ? options.preTriggerInclude.join(",") : options.preTriggerInclude; | ||
} | ||
if (options.postTriggerInclude) { | ||
headers[Constants.HttpHeaders.PostTriggerInclude] = options.postTriggerInclude.constructor === Array? options.postTriggerInclude.join(","): options.postTriggerInclude; | ||
headers[Constants.HttpHeaders.PostTriggerInclude] = options.postTriggerInclude.constructor === Array ? options.postTriggerInclude.join(",") : options.postTriggerInclude; | ||
} | ||
@@ -211,7 +212,7 @@ | ||
} | ||
if (options.indexingDirective) { | ||
headers[Constants.HttpHeaders.IndexingDirective] = options.indexingDirective; | ||
} | ||
// TODO: add consistency level validation. | ||
@@ -221,7 +222,7 @@ if (options.consistencyLevel) { | ||
} | ||
if (options.resourceTokenExpirySeconds) { | ||
headers[Constants.HttpHeaders.ResourceTokenExpiry] = options.resourceTokenExpirySeconds; | ||
} | ||
// TODO: add session token automatic handling in case of session consistency. | ||
@@ -231,15 +232,15 @@ if (options.sessionToken) { | ||
} | ||
if (options.enableScanInQuery) { | ||
headers[Constants.HttpHeaders.EnableScanInQuery] = options.enableScanInQuery; | ||
} | ||
if (documentClient.masterKey) { | ||
headers[Constants.HttpHeaders.XDate] = new Date().toUTCString(); | ||
} | ||
if (documentClient.masterKey || documentClient.resourceTokens) { | ||
headers[Constants.HttpHeaders.Authorization] = encodeURIComponent(AuthHandler.getAuthorizationHeader(documentClient, verb, path, resourceId, resourceType, headers)); | ||
} | ||
if (verb === "post" || verb === "put") { | ||
@@ -250,3 +251,3 @@ if (!headers[Constants.HttpHeaders.ContentType]) { | ||
} | ||
if (!headers[Constants.HttpHeaders.Accept]) { | ||
@@ -258,6 +259,6 @@ headers[Constants.HttpHeaders.Accept] = Constants.MediaTypes.Json; | ||
}, | ||
/** @ignore */ | ||
parsePath: function(resourcePath) { | ||
if (resourcePath.length == 0) { | ||
if (resourcePath.length === 0) { | ||
/* for DatabaseAccount case, both type and objectBody will be undefined. */ | ||
@@ -279,3 +280,3 @@ return { | ||
/* | ||
/ The path will be in the form of /[resourceType]/[resourceId]/ .... /[resourceType]//[resourceType]/[resourceId]/ .... /[resourceType]/[resourceId]/ | ||
/ The path will be in the form of /[resourceType]/[resourceId]/ .... /[resourceType]//[resourceType]/[resourceId]/ .... /[resourceType]/[resourceId]/ | ||
/ or /[resourceType]/[resourceId]/ .... /[resourceType]/[resourceId]/[resourceType]/[resourceId]/ .... /[resourceType]/[resourceId]/ | ||
@@ -297,3 +298,3 @@ / The result of split will be in the form of [[[resourceType], [resourceId] ... ,[resourceType], [resourceId], ""] | ||
} | ||
var result = { | ||
@@ -306,65 +307,64 @@ type: type, | ||
}; | ||
return result; | ||
}, | ||
/** @ignore */ | ||
getAttachmentIdFromMediaId: function(mediaId) { | ||
var buffer = new Buffer(mediaId, 'base64'); | ||
var buffer = new Buffer(mediaId, "base64"); | ||
var ResoureIdLength = 20; | ||
var attachmentId = ""; | ||
if (buffer.length > ResoureIdLength) { | ||
attachmentId = buffer.toString('base64', 0, ResoureIdLength) | ||
} | ||
else { | ||
attachmentId = buffer.toString("base64", 0, ResoureIdLength); | ||
} else { | ||
attachmentId = mediaId; | ||
} | ||
return attachmentId; | ||
}, | ||
/** @ignore */ | ||
getHexaDigit: function() { | ||
return Math.floor(Math.random() * 16).toString(16); | ||
}, | ||
/** @ignore */ | ||
generateGuidId: function() { | ||
var id = ""; | ||
for (var i = 0;i < 8; i++) { | ||
id+= Base.getHexaDigit(); | ||
} | ||
id+= "-"; | ||
for (var i = 0;i < 4; i++) { | ||
id+= Base.getHexaDigit(); | ||
} | ||
id+= "-"; | ||
for (var i = 0;i < 4; i++) { | ||
id+= Base.getHexaDigit(); | ||
} | ||
id+= "-"; | ||
for (var i = 0;i < 4; i++) { | ||
id+= Base.getHexaDigit(); | ||
} | ||
id+= "-"; | ||
for (var i = 0;i < 12; i++) { | ||
id+= Base.getHexaDigit(); | ||
} | ||
return id; | ||
} | ||
/** @ignore */ | ||
getHexaDigit: function() { | ||
return Math.floor(Math.random() * 16).toString(16); | ||
}, | ||
/** @ignore */ | ||
generateGuidId: function() { | ||
var id = ""; | ||
for (var i = 0; i < 8; i++) { | ||
id += Base.getHexaDigit(); | ||
} | ||
id += "-"; | ||
for (var i = 0; i < 4; i++) { | ||
id += Base.getHexaDigit(); | ||
} | ||
id += "-"; | ||
for (var i = 0; i < 4; i++) { | ||
id += Base.getHexaDigit(); | ||
} | ||
id += "-"; | ||
for (var i = 0; i < 4; i++) { | ||
id += Base.getHexaDigit(); | ||
} | ||
id += "-"; | ||
for (var i = 0; i < 12; i++) { | ||
id += Base.getHexaDigit(); | ||
} | ||
return id; | ||
} | ||
}; | ||
//SCRIPT END | ||
if (typeof exports !== "undefined") { | ||
if (typeof exports !== "undefined") { | ||
module.exports = Base; | ||
} |
@@ -18,3 +18,3 @@ //---------------------------------------------------------------------------- | ||
TextHtml: "text/html", | ||
TextPlain: "text/plain", | ||
TextPlain: "text/plain", | ||
Xml: "application/xml" | ||
@@ -42,3 +42,3 @@ }, | ||
UserAgent: "User-Agent", | ||
IfModified_since: "If-Modified-Since", | ||
IfModifiedSince: "If-Modified-Since", | ||
IfMatch: "If-Match", | ||
@@ -108,6 +108,6 @@ IfNoneMatch: "If-None-Match", | ||
Version: "x-ms-version", | ||
//Quota Info | ||
MaxEntityCount: "x-ms-root-entity-max-count", | ||
CurrentEntityCount: "x-ms-root-entity-current-count", | ||
CurrentEntityCount: "x-ms-root-entity-current-count", | ||
CollectionQuotaInMb: "x-ms-collection-quota-mb", | ||
@@ -122,8 +122,8 @@ CollectionCurrentUsageInMb: "x-ms-collection-usage-mb", | ||
}, | ||
CurrentVersion: "2015-04-08", | ||
UserAgent: "documentdb-nodejs-sdk-1.0.2" | ||
} | ||
UserAgent: "documentdb-nodejs-sdk-1.0.3" | ||
}; | ||
//SCRIPT END | ||
@@ -130,0 +130,0 @@ |
@@ -5,3 +5,3 @@ //---------------------------------------------------------------------------- | ||
'use strict'; | ||
"use strict"; | ||
@@ -11,3 +11,3 @@ var Base = require("./base"); | ||
var AzureDocuments = Base.defineClass(null, null, | ||
var AzureDocuments = Base.defineClass(null, null, | ||
{ | ||
@@ -17,6 +17,6 @@ /** | ||
* @global | ||
* @property {string} DatabasesLink - The self-link for Databases in the databaseAccount. | ||
* @property {string} MediaLink - The self-link for Media in the databaseAccount. | ||
* @property {number} MaxMediaStorageUsageInMB - Attachment content (media) storage quota in MBs ( Retrieved from gateway ). | ||
* @property {number} CurrentMediaStorageUsageInMB - <p> Current attachment content (media) usage in MBs (Retrieved from gateway )<br> | ||
* @property {string} DatabasesLink - The self-link for Databases in the databaseAccount. | ||
* @property {string} MediaLink - The self-link for Media in the databaseAccount. | ||
* @property {number} MaxMediaStorageUsageInMB - Attachment content (media) storage quota in MBs ( Retrieved from gateway ). | ||
* @property {number} CurrentMediaStorageUsageInMB - <p> Current attachment content (media) usage in MBs (Retrieved from gateway )<br> | ||
Value is returned from cached information updated periodically and is not guaranteed to be real time. </p> | ||
@@ -28,3 +28,3 @@ * @property {object} ConsistencyPolicy - Gets the UserConsistencyPolicy settings. | ||
*/ | ||
DatabaseAccount : Base.defineClass(function() { | ||
DatabaseAccount: Base.defineClass(function() { | ||
Object.defineProperty(this, "DatabasesLink", { | ||
@@ -36,4 +36,4 @@ value: "", | ||
}); | ||
Object.defineProperty(this, "MediaLink", { | ||
Object.defineProperty(this, "MediaLink", { | ||
value: "", | ||
@@ -44,4 +44,4 @@ writable: true, | ||
}); | ||
Object.defineProperty(this, "MaxMediaStorageUsageInMB", { | ||
Object.defineProperty(this, "MaxMediaStorageUsageInMB", { | ||
value: 0, | ||
@@ -52,4 +52,4 @@ writable: true, | ||
}); | ||
Object.defineProperty(this, "CurrentMediaStorageUsageInMB", { | ||
Object.defineProperty(this, "CurrentMediaStorageUsageInMB", { | ||
value: 0, | ||
@@ -60,4 +60,4 @@ writable: true, | ||
}); | ||
Object.defineProperty(this, "ConsumedDocumentStorageInMB", { | ||
Object.defineProperty(this, "ConsumedDocumentStorageInMB", { | ||
value: 0, | ||
@@ -68,4 +68,4 @@ writable: true, | ||
}); | ||
Object.defineProperty(this, "ReservedDocumentStorageInMB", { | ||
Object.defineProperty(this, "ReservedDocumentStorageInMB", { | ||
value: 0, | ||
@@ -76,4 +76,4 @@ writable: true, | ||
}); | ||
Object.defineProperty(this, "ProvisionedDocumentStorageInMB", { | ||
Object.defineProperty(this, "ProvisionedDocumentStorageInMB", { | ||
value: 0, | ||
@@ -84,4 +84,4 @@ writable: true, | ||
}); | ||
Object.defineProperty(this, "ConsistencyPolicy", { | ||
Object.defineProperty(this, "ConsistencyPolicy", { | ||
value: "", | ||
@@ -93,3 +93,3 @@ writable: true, | ||
}), | ||
/** | ||
@@ -104,7 +104,7 @@ * <p>Represents the consistency levels supported for DocumentDB client operations.<br> | ||
* @property Session Session Consistency guarantees monotonic reads (you never read old data, then new, then old again), monotonic writes (writes are ordered) | ||
and read your writes (your writes are immediately visible to your reads) within any single session. | ||
* @property Eventual Eventual Consistency guarantees that reads will return a subset of writes. All writes | ||
and read your writes (your writes are immediately visible to your reads) within any single session. | ||
* @property Eventual Eventual Consistency guarantees that reads will return a subset of writes. All writes | ||
will be eventually be available for reads. | ||
*/ | ||
ConsistencyLevel : Object.freeze({ | ||
ConsistencyLevel: Object.freeze({ | ||
Strong: "Strong", | ||
@@ -115,4 +115,4 @@ BoundedStaleness: "BoundedStaleness", | ||
}), | ||
/** | ||
@@ -123,3 +123,3 @@ * Specifies the supported indexing modes. | ||
* @property Consistent <p>Index is updated synchronously with a create or update operation. <br> | ||
With consistent indexing, query behavior is the same as the default consistency level for the collection. The index is | ||
With consistent indexing, query behavior is the same as the default consistency level for the collection. The index is | ||
always kept up to date with the data. </p> | ||
@@ -129,25 +129,25 @@ * @property Lazy <p>Index is updated asynchronously with respect to a create or update operation. <br> | ||
*/ | ||
IndexingMode : Object.freeze({ | ||
IndexingMode: Object.freeze({ | ||
Consistent: "consistent", | ||
Lazy: "lazy", | ||
Lazy: "lazy" | ||
}), | ||
/** | ||
* Specifies the supported Index types. | ||
* @readonly | ||
/** | ||
* Specifies the supported Index types. | ||
* @readonly | ||
* @enum {string} | ||
* @property Hash This is supplied for a path which has no sorting requirement. | ||
* This kind of an index has better precision than corresponding range index. | ||
* | ||
* @property Range This is supplied for a path which requires sorting. | ||
*/ | ||
IndexType : Object.freeze({ | ||
* @property Hash This is supplied for a path which has no sorting requirement. | ||
* This kind of an index has better precision than corresponding range index. | ||
* | ||
* @property Range This is supplied for a path which requires sorting. | ||
*/ | ||
IndexType: Object.freeze({ | ||
Hash: "Hash", | ||
Range: "Range", | ||
Range: "Range" | ||
}), | ||
ConnectionMode : Object.freeze({ | ||
Gateway: 0, | ||
}), | ||
ConnectionMode: Object.freeze({ | ||
Gateway: 0 | ||
}), | ||
@@ -157,5 +157,5 @@ QueryCompatibilityMode: Object.freeze({ | ||
Query: 1, | ||
SqlQuery: 2, | ||
SqlQuery: 2 | ||
}), | ||
/** | ||
@@ -166,11 +166,11 @@ * Enum for media read mode values. | ||
* @property Buffered Content is buffered at the client and not directly streamed from the content store. | ||
<p>Use Buffered to reduce the time taken to read and write media files.</p> | ||
<p>Use Buffered to reduce the time taken to read and write media files.</p> | ||
* @property Streamed Content is directly streamed from the content store without any buffering at the client. | ||
<p>Use Streamed to reduce the client memory overhead of reading and writing media files. </p> | ||
*/ | ||
MediaReadMode : Object.freeze({ | ||
*/ | ||
MediaReadMode: Object.freeze({ | ||
Buffered: "Buffered", | ||
Streamed: "Streamed" | ||
}), | ||
/** | ||
@@ -183,3 +183,3 @@ * Enum for permission mode values. | ||
* @property All Permission applicable for all operations. | ||
*/ | ||
*/ | ||
PermissionMode: Object.freeze({ | ||
@@ -201,3 +201,3 @@ None: "none", | ||
Pre: "pre", | ||
Post: "post", | ||
Post: "post" | ||
}), | ||
@@ -223,3 +223,3 @@ | ||
}), | ||
/** | ||
@@ -243,3 +243,3 @@ * Enum for udf type values. | ||
*/ | ||
ConnectionPolicy : Base.defineClass(function() { | ||
ConnectionPolicy: Base.defineClass(function() { | ||
Object.defineProperty(this, "_defaultRequestTimeout", { | ||
@@ -270,3 +270,3 @@ value: 60000, | ||
if (typeof exports !== "undefined") { | ||
module.exports = AzureDocuments; | ||
module.exports = AzureDocuments; | ||
} |
@@ -1,4 +0,4 @@ | ||
'use strict'; | ||
"use strict"; | ||
var Client = require('./documentclient') | ||
var Client = require("./documentclient"); | ||
@@ -5,0 +5,0 @@ if (typeof exports !== "undefined") { |
@@ -5,6 +5,6 @@ //---------------------------------------------------------------------------- | ||
'use strict'; | ||
"use strict"; | ||
var Base = require("./base") | ||
, Constants = require('./constants'); | ||
, Constants = require("./constants"); | ||
@@ -42,7 +42,7 @@ //SCRIPT START | ||
this.reset(); | ||
} | ||
} | ||
this._forEachImplementation(callback); | ||
}, | ||
/** | ||
@@ -59,3 +59,3 @@ * Execute a provided function on the next element in the QueryIterator. | ||
} | ||
if (this._state === this._states.start || (this.continuation && this._state === this._states.inProgress)) { | ||
@@ -66,3 +66,3 @@ this._fetchMore(function(err, resources, headers){ | ||
} | ||
that.resources = resources; | ||
@@ -73,7 +73,6 @@ if (that.resources.length === 0) { | ||
callback(undefined, undefined); | ||
return; | ||
} else { | ||
that.nextItem(callback); | ||
return; | ||
} | ||
return undefined; | ||
} | ||
@@ -88,3 +87,3 @@ | ||
}, | ||
/** | ||
@@ -95,7 +94,7 @@ * Retrieve the current element on the QueryIterator. | ||
* @returns {Object} The current resource in the QueryIterator, undefined if there isn't. | ||
*/ | ||
*/ | ||
current: function(){ | ||
return this.resources[this.current]; | ||
}, | ||
/** | ||
@@ -106,7 +105,7 @@ * Determine if there are still remaining resources to processs based on the value of the continuation token or the elements remaining on the current batch in the QueryIterator. | ||
* @returns {Boolean} true if there is other elements to process in the QueryIterator. | ||
*/ | ||
*/ | ||
hasMoreResults: function() { | ||
return this._state === this._states.start || this.continuation !== undefined || this.current < this.resources.length; | ||
}, | ||
/** | ||
@@ -121,7 +120,7 @@ * Retrieve all the elements of the feed and pass them as an array to a function | ||
this.reset(); | ||
} | ||
} | ||
this._toArrayImplementation(callback); | ||
}, | ||
/** | ||
@@ -134,3 +133,2 @@ * Retrieve the next batch of the feed and pass them as an array to a function | ||
executeNext: function(callback) { | ||
var that = this; | ||
this._fetchMore(function(err, resources, responseHeaders) { | ||
@@ -140,3 +138,3 @@ if(err) { | ||
} | ||
callback(undefined, resources, responseHeaders); | ||
@@ -157,3 +155,3 @@ }); | ||
}, | ||
/** @ignore */ | ||
@@ -167,3 +165,3 @@ _toArrayImplementation: function(callback){ | ||
} | ||
that.resources = that.resources.concat(resources); | ||
@@ -177,3 +175,3 @@ that._toArrayImplementation(callback); | ||
}, | ||
/** @ignore */ | ||
@@ -187,3 +185,3 @@ _forEachImplementation: function(callback){ | ||
} | ||
that.resources = resources; | ||
@@ -193,6 +191,6 @@ while (that.current < that.resources.length) { | ||
if (callback(undefined, that.resources[that.current++]) === false) { | ||
return; | ||
return undefined; | ||
} | ||
} | ||
that._forEachImplementation(callback); | ||
@@ -205,3 +203,3 @@ }); | ||
}, | ||
/** @ignore */ | ||
@@ -216,3 +214,3 @@ _fetchMore: function(callback){ | ||
} | ||
that.continuation = responseHeaders[Constants.HttpHeaders.Continuation]; | ||
@@ -219,0 +217,0 @@ that._state = that._states.inProgress; |
@@ -5,10 +5,10 @@ //---------------------------------------------------------------------------- | ||
'use strict'; | ||
"use strict"; | ||
var Documents = require('./documents') | ||
var Documents = require("./documents") | ||
, Constants = require("./constants") | ||
, https = require("https") | ||
, url = require("url") | ||
, url = require("url") | ||
, querystring = require("querystring"); | ||
// We don't turn off agent because we want the pooling benefits. | ||
@@ -36,12 +36,12 @@ https.globalAgent.maxSockets = 10000; | ||
var isMedia = ( requestOptions.path.indexOf("media") > -1 ); | ||
var httpsRequest = https.request(requestOptions, function(response) { | ||
// In case of media response, return the stream to the user and the user will need to handle reading the stream. | ||
if(isMedia && connectionPolicy.MediaReadMode === Documents.MediaReadMode.Streamed){ | ||
callback(undefined, response, response.headers); | ||
return; | ||
if (isMedia && connectionPolicy.MediaReadMode === Documents.MediaReadMode.Streamed) { | ||
callback(undefined, response, response.headers); | ||
return; | ||
} | ||
var data = ""; | ||
response.on("data", function(chunk) { | ||
response.on("data", function(chunk) { | ||
data += chunk; | ||
@@ -51,3 +51,3 @@ }); | ||
if (response.statusCode >= 400) { | ||
callback({code:response.statusCode, body:data}, undefined, response.headers); | ||
callback({code: response.statusCode, body: data}, undefined, response.headers); | ||
return; | ||
@@ -64,11 +64,11 @@ } | ||
} catch (exception) { | ||
callback(exception); | ||
return; | ||
callback(exception); | ||
return; | ||
} | ||
return callback(undefined, result, response.headers); | ||
callback(undefined, result, response.headers); | ||
}); | ||
}); | ||
httpsRequest.on('socket', function(socket) { | ||
httpsRequest.on("socket", function(socket) { | ||
if (isMedia) { | ||
@@ -79,10 +79,10 @@ socket.setTimeout(connectionPolicy.MediaRequestTimeout); | ||
} | ||
socket.on('timeout', function() { | ||
socket.on("timeout", function() { | ||
httpsRequest.abort(); | ||
}); | ||
}); | ||
httpsRequest.on("error", callback); | ||
return httpsRequest; | ||
return httpsRequest; | ||
} | ||
@@ -102,8 +102,8 @@ | ||
*/ | ||
request: function(connectionPolicy, method, url, path, data, queryParams, headers, callback) { | ||
request: function (connectionPolicy, method, url, path, data, queryParams, headers, callback) { | ||
var body; | ||
if (data) { | ||
body = bodyFromData(data); | ||
if (!body) return callback({message:"parameter data must be a javascript object, string, Buffer, or stream"}); | ||
if (!body) return callback({ message: "parameter data must be a javascript object, string, Buffer, or stream" }); | ||
} | ||
@@ -116,13 +116,10 @@ | ||
buffer = body; | ||
} | ||
else if (body.pipe) { | ||
} else if (body.pipe) { | ||
// it is a stream | ||
stream = body; | ||
} | ||
else if (typeof body === "string") { | ||
} else if (typeof body === "string") { | ||
buffer = new Buffer(body, "utf8"); | ||
} else { | ||
callback({ message: "body must be string, Buffer, or stream" }); | ||
} | ||
else { | ||
callback({message:"body must be string, Buffer, or stream"}); | ||
} | ||
} | ||
@@ -134,7 +131,7 @@ | ||
requestOptions.headers = headers; | ||
if(queryParams) { | ||
requestOptions.path += "?" + querystring.stringify(queryParams); | ||
if (queryParams) { | ||
requestOptions.path += "?" + querystring.stringify(queryParams); | ||
} | ||
if (buffer) { | ||
@@ -145,3 +142,3 @@ requestOptions.headers[Constants.HttpHeaders.ContentLength] = buffer.length; | ||
httpsRequest.end(); | ||
} else if(stream) { | ||
} else if (stream) { | ||
var httpsRequest = createRequestObject(connectionPolicy, requestOptions, callback); | ||
@@ -154,3 +151,3 @@ stream.pipe(httpsRequest); | ||
} | ||
} | ||
}; | ||
@@ -157,0 +154,0 @@ if (typeof exports !== "undefined") { |
{ | ||
"name": "documentdb", | ||
"description": "Node.js client for documentdb", | ||
"keywords": [ | ||
"name": "documentdb", | ||
"description": "Node.js client for documentdb", | ||
"keywords": [ | ||
"documentdb", | ||
@@ -12,3 +12,3 @@ "document database", | ||
], | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"author": "Microsoft Corporation", | ||
@@ -20,10 +20,20 @@ "main": "./index.js", | ||
"devDependencies": { | ||
"eslint": "*", | ||
"grunt": "^0.4.5", | ||
"grunt-eslint": "^13.0.0", | ||
"jsdoc": "*", | ||
"load-grunt-tasks": "^3.1.0", | ||
"mocha": "*", | ||
"jsdoc": "*", | ||
"eslint": "*" | ||
"time-grunt": "^1.2.0" | ||
}, | ||
"repository" : { "type" : "git", | ||
"url" : "https://github.com/Azure/azure-documentdb-node" }, | ||
"licenses" : [ { "type" : "Apache License, Version 2.0", | ||
"url" : "http://www.apache.org/licenses/LICENSE-2.0" } ] | ||
} | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/Azure/azure-documentdb-node" | ||
}, | ||
"licenses": [ | ||
{ | ||
"type": "Apache License, Version 2.0", | ||
"url": "http://www.apache.org/licenses/LICENSE-2.0" | ||
} | ||
] | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
223339
17
3872
7