diff --git a/.npmignore b/.npmignore index 8e207402..66b1d0b8 100644 --- a/.npmignore +++ b/.npmignore @@ -4,8 +4,5 @@ # Node # node_modules/ -# Test folder # -test/ - # Examples # examples/blobuploader/ \ No newline at end of file diff --git a/ChangeLog.txt b/ChangeLog.txt index 87b67e9b..0269f9d9 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,6 +1,14 @@ Note: This is an Azure Storage only package. The all up Azure node sdk still has the old storage bits in there. In a future release, those storage bits will be removed and an npm dependency to this storage node sdk will be taken. This is a CTP v1 release and the changes described below indicate the changes from the Azure node SDK 0.9.8 available here - https://github.com/Azure/azure-sdk-for-node. +2014.07.01 Version 0.2.1 + +ALL +* Fixed a bug with casing which caused the module to fail on linux machines. + +BLOB +* Fixed a bug which failed to upload an empty blob for empty block blob files uploaded using createBlockBlobFromFile when retry policies were used. + 2014.06.16 Version 0.2.0 ALL diff --git a/gruntfile.js b/gruntfile.js index ac8a79cf..c7524df4 100644 --- a/gruntfile.js +++ b/gruntfile.js @@ -28,11 +28,11 @@ module.exports = function(grunt) { src: [ "README.md", "lib/azure-storage.js", - "lib/common/lib/services/filters/retrypolicyfilter.js", - "lib/common/lib/services/filters/linearretrypolicyfilter.js", - "lib/common/lib/services/filters/exponentialretrypolicyfilter.js", - "lib/common/lib/services/storageutilities.js", - "lib/common/lib/util/date.js", + "lib/common/filters/retrypolicyfilter.js", + "lib/common/filters/linearretrypolicyfilter.js", + "lib/common/filters/exponentialretrypolicyfilter.js", + "lib/common/services/storageutilities.js", + "lib/common/util/date.js", "lib/services/blob/blobservice.js", "lib/services/blob/blobutilities.js", "lib/services/queue/queueservice.js", diff --git a/lib/azure-storage.js b/lib/azure-storage.js index c673bc79..4f6f691d 100644 --- a/lib/azure-storage.js +++ b/lib/azure-storage.js @@ -174,7 +174,7 @@ exports.createQueueServiceWithSas = function(hostUri, sasToken) { * For example, HTTP status codes and headers. */ -var azureCommon = require('./common/lib/common'); +var azureCommon = require('./common/common'); exports.Constants = azureCommon.Constants; exports.StorageUtilities = azureCommon.StorageUtilities; @@ -183,19 +183,8 @@ exports.SR = azureCommon.SR; exports.StorageServiceClient = azureCommon.StorageServiceClient; exports.Logger = azureCommon.Logger; exports.WebResource = azureCommon.WebResource; -exports.Validate = azureCommon.validate; exports.date = azureCommon.date; -exports.ServiceSettings = azureCommon.ServiceSettings; -exports.StorageServiceSettings = azureCommon.StorageServiceSettings; - -exports.AclResult = require('./common/lib/services/aclresult'); - -// Credentials -exports.SharedAccessSignature = require('./common/lib/services/sharedaccesssignature'); -exports.SharedKey = require('./common/lib/services/sharedkey'); -exports.SharedKeyTable = require('./services/table/internal/sharedkeytable'); - // Other filters exports.LinearRetryPolicyFilter = azureCommon.LinearRetryPolicyFilter; exports.ExponentialRetryPolicyFilter = azureCommon.ExponentialRetryPolicyFilter; diff --git a/lib/common/lib/common.js b/lib/common/common.js similarity index 59% rename from lib/common/lib/common.js rename to lib/common/common.js index 690389a4..6c4a19ea 100644 --- a/lib/common/lib/common.js +++ b/lib/common/common.js @@ -28,33 +28,39 @@ if (nodeVersion.major === 0 && nodeVersion.minor > 8 && !(nodeVersion.minor > 10 exports.xmlbuilder = require('xmlbuilder'); exports.xml2js = require('xml2js'); -exports.Constants = require('./util/constants'); -exports.SR = require('./util/sr'); exports.Logger = require('./diagnostics/logger'); -exports.date = require('./util/date'); - exports.WebResource = require('./http/webresource'); + +// Services exports.StorageServiceClient = require('./services/storageserviceclient'); -exports.ServiceSettings = require('./services/servicesettings'); -exports.StorageServiceSettings = require('./services/storageservicesettings'); -exports.StorageUtilities = require('./services/StorageUtilities'); +// Models +exports.ServicePropertiesResult = require('./models/servicepropertiesresult'); +exports.ServiceStatsParser = require('./models/servicestatsparser'); +exports.AclResult = require('./models/aclresult'); -exports.ServicePropertiesResult = require('./services/servicepropertiesresult'); -exports.ServiceStatsParser = require('./services/servicestatsparser'); +// Filters +exports.LinearRetryPolicyFilter = require('./filters/linearretrypolicyfilter'); +exports.ExponentialRetryPolicyFilter = require('./filters/exponentialretrypolicyfilter'); +exports.RetryPolicyFilter = require('./filters/retrypolicyfilter'); -// Other filters -exports.LinearRetryPolicyFilter = require('./services/filters/linearretrypolicyfilter'); -exports.ExponentialRetryPolicyFilter = require('./services/filters/exponentialretrypolicyfilter'); -exports.RetryPolicyFilter = require('./services/filters/retrypolicyfilter'); +// Signing +exports.SharedAccessSignature = require('./signing/sharedaccesssignature'); +exports.SharedKey = require('./signing/sharedkey'); -exports.HmacSha256Sign = require('./services/hmacsha256sign'); -exports.ISO8061Date = require('./util/iso8061date'); +// Streams +exports.BatchOperation = require('./streams/batchoperation'); +exports.ChunkAllocator = require('./streams/chunkallocator'); +exports.ChunkStream = require('./streams/chunkstream'); +exports.ChunkStreamWithStream = require('./streams/chunkstreamwithstream'); +exports.FileReadStream = require('./streams/filereadstream'); +exports.SpeedSummary = require('./streams/speedsummary'); +// Utilities +exports.Constants = require('./util/constants'); +exports.SR = require('./util/sr'); +exports.date = require('./util/date'); +exports.ISO8061Date = require('./util/iso8061date'); exports.util = require('./util/util'); exports.validate = require('./util/validate'); -exports.SR = require('./util/sr'); -exports.AclResult = require('./services/aclresult'); - -exports.SharedAccessSignature = require('./services/sharedaccesssignature'); -exports.SharedKey = require('./services/sharedkey'); +exports.StorageUtilities = require('./util/storageutilities'); \ No newline at end of file diff --git a/lib/common/lib/diagnostics/logger.js b/lib/common/diagnostics/logger.js similarity index 100% rename from lib/common/lib/diagnostics/logger.js rename to lib/common/diagnostics/logger.js diff --git a/lib/common/lib/services/filters/exponentialretrypolicyfilter.js b/lib/common/filters/exponentialretrypolicyfilter.js similarity index 100% rename from lib/common/lib/services/filters/exponentialretrypolicyfilter.js rename to lib/common/filters/exponentialretrypolicyfilter.js diff --git a/lib/common/lib/services/filters/linearretrypolicyfilter.js b/lib/common/filters/linearretrypolicyfilter.js similarity index 100% rename from lib/common/lib/services/filters/linearretrypolicyfilter.js rename to lib/common/filters/linearretrypolicyfilter.js diff --git a/lib/common/lib/services/filters/retrypolicyfilter.js b/lib/common/filters/retrypolicyfilter.js similarity index 98% rename from lib/common/lib/services/filters/retrypolicyfilter.js rename to lib/common/filters/retrypolicyfilter.js index 00ddd405..f3fc5609 100644 --- a/lib/common/lib/services/filters/retrypolicyfilter.js +++ b/lib/common/filters/retrypolicyfilter.js @@ -14,9 +14,9 @@ // limitations under the License. // -var azureutil = require('../../util/util'); -var Constants = require('../../util/constants'); -var StorageUtilities = require('../../services/StorageUtilities'); +var azureutil = require('../util/util'); +var Constants = require('../util/constants'); +var StorageUtilities = require('../util/storageutilities'); var extend = require('util')._extend; /** diff --git a/lib/common/lib/http/webresource.js b/lib/common/http/webresource.js similarity index 100% rename from lib/common/lib/http/webresource.js rename to lib/common/http/webresource.js diff --git a/lib/common/lib/services/aclresult.js b/lib/common/models/aclresult.js similarity index 88% rename from lib/common/lib/services/aclresult.js rename to lib/common/models/aclresult.js index fa57c9d1..105d164f 100644 --- a/lib/common/lib/services/aclresult.js +++ b/lib/common/models/aclresult.js @@ -16,19 +16,14 @@ // Module dependencies. var _ = require('underscore'); +var xmlbuilder = require('xmlbuilder'); -var azureCommon = require('./../common'); -var xmlbuilder = azureCommon.xmlbuilder; -var azureutil = azureCommon.util; -var Constants = azureCommon.Constants; +var azureutil = require('../util/util'); +var ISO8061Date = require('../util/iso8061date'); +var Constants = require('../util/constants'); var AclConstants = Constants.AclConstants; -var ISO8061Date = azureCommon.ISO8061Date; -function AclResult(signedIdentifiers) { - if (signedIdentifiers) { - this.signedIdentifiers = signedIdentifiers; - } -} +exports = module.exports; /** * Builds an XML representation for container acl permissions. @@ -36,7 +31,7 @@ function AclResult(signedIdentifiers) { * @param {array} entity The signed identifiers. * @return {string} The XML container acl permissions. */ -AclResult.serialize = function (signedIdentifiersJs) { +exports.serialize = function (signedIdentifiersJs) { var doc = xmlbuilder.create(); doc = doc.begin(AclConstants.SIGNED_IDENTIFIERS_ELEMENT, { version: '1.0', encoding: 'utf-8' }); @@ -93,7 +88,7 @@ AclResult.serialize = function (signedIdentifiersJs) { return doc.doc().toString(); }; -AclResult.parse = function (signedIdentifiersXml) { +exports.parse = function (signedIdentifiersXml) { var signedIdentifiers = []; signedIdentifiersXml = azureutil.tryGetValueChain(signedIdentifiersXml, [ 'SignedIdentifiers', 'SignedIdentifier' ]); @@ -126,6 +121,4 @@ AclResult.parse = function (signedIdentifiersXml) { } return signedIdentifiers; -}; - -module.exports = AclResult; \ No newline at end of file +}; \ No newline at end of file diff --git a/lib/common/lib/services/servicepropertiesresult.js b/lib/common/models/servicepropertiesresult.js similarity index 100% rename from lib/common/lib/services/servicepropertiesresult.js rename to lib/common/models/servicepropertiesresult.js diff --git a/lib/common/lib/services/servicestatsparser.js b/lib/common/models/servicestatsparser.js similarity index 100% rename from lib/common/lib/services/servicestatsparser.js rename to lib/common/models/servicestatsparser.js diff --git a/lib/common/lib/services/servicesettings.js b/lib/common/services/servicesettings.js similarity index 100% rename from lib/common/lib/services/servicesettings.js rename to lib/common/services/servicesettings.js diff --git a/lib/common/lib/services/storageserviceclient.js b/lib/common/services/storageserviceclient.js similarity index 98% rename from lib/common/lib/services/storageserviceclient.js rename to lib/common/services/storageserviceclient.js index c20aa018..1e70b0f6 100644 --- a/lib/common/lib/services/storageserviceclient.js +++ b/lib/common/services/storageserviceclient.js @@ -33,10 +33,10 @@ var WebResource = require('../http/webresource'); var ServiceSettings = require('./servicesettings'); var StorageServiceSettings = require('./storageservicesettings'); var Constants = require('../util/constants'); -var StorageUtilities = require('./storageutilities'); +var StorageUtilities = require('../util/storageutilities'); -var SharedKey = require('./sharedkey'); -var SharedAccessSignature = require('./sharedaccesssignature'); +var SharedKey = require('../signing/sharedkey'); +var SharedAccessSignature = require('../signing/sharedaccesssignature'); var HeaderConstants = Constants.HeaderConstants; var QueryStringConstants = Constants.QueryStringConstants; @@ -46,7 +46,7 @@ var defaultRequestLocationMode = Constants.RequestLocationMode.PRIMARY_ONLY; var Logger = require('../diagnostics/logger'); -var moduleVersion = require('../../../../package.json').version; +var moduleVersion = require('../../../package.json').version; /** * Creates a new StorageServiceClient object. @@ -374,7 +374,7 @@ StorageServiceClient.prototype._performRequest = function (webResource, body, op var sendStream = function () { // NOTE: workaround for an unexpected EPIPE exception when piping streams larger than 29 MB - if (finalRequestOptions.headers['content-length'] && finalRequestOptions.headers['content-length'] < 29 * 1024 * 1024) { + if (!azureutil.objectIsNull(finalRequestOptions.headers['content-length']) && finalRequestOptions.headers['content-length'] < 29 * 1024 * 1024) { body.outputStream.pipe(buildRequest()); } else { sendUnchunked(); @@ -382,10 +382,15 @@ StorageServiceClient.prototype._performRequest = function (webResource, body, op }; if (!body.outputStream.readable) { - // This will wait until we know the readable stream is actually valid before piping - body.outputStream.on('open', function () { - sendStream(); - }); + // if the content length is zero, build the request and don't send a body + if (finalRequestOptions.headers['content-length'] === 0) { + buildRequest(); + } else { + // otherwise, wait until we know the readable stream is actually valid before piping + body.outputStream.on('open', function () { + sendStream(); + }); + } } else { sendStream(); } diff --git a/lib/common/lib/services/storageservicesettings.js b/lib/common/services/storageservicesettings.js similarity index 100% rename from lib/common/lib/services/storageservicesettings.js rename to lib/common/services/storageservicesettings.js diff --git a/lib/common/lib/services/hmacsha256sign.js b/lib/common/signing/hmacsha256sign.js similarity index 100% rename from lib/common/lib/services/hmacsha256sign.js rename to lib/common/signing/hmacsha256sign.js diff --git a/lib/common/lib/services/sharedaccesssignature.js b/lib/common/signing/sharedaccesssignature.js similarity index 100% rename from lib/common/lib/services/sharedaccesssignature.js rename to lib/common/signing/sharedaccesssignature.js diff --git a/lib/common/lib/services/sharedkey.js b/lib/common/signing/sharedkey.js similarity index 100% rename from lib/common/lib/services/sharedkey.js rename to lib/common/signing/sharedkey.js diff --git a/lib/services/blob/internal/batchoperation.js b/lib/common/streams/batchoperation.js similarity index 97% rename from lib/services/blob/internal/batchoperation.js rename to lib/common/streams/batchoperation.js index ad76d10f..12f5b75d 100644 --- a/lib/services/blob/internal/batchoperation.js +++ b/lib/common/streams/batchoperation.js @@ -20,15 +20,15 @@ var https = require('https'); var EventEmitter = require('events').EventEmitter; var os = require('os'); -var azureCommon = require('./../../../common/lib/common'); -var utils = azureCommon.util; -var Logger = azureCommon.Logger; +var azureutil = require('../util/util'); +var Logger = require('../diagnostics/logger'); +var Constants = require('../util/constants'); -var DEFAULT_OPERATION_MEMORY_USAGE = azureCommon.Constants.BlobConstants.DEFAULT_WRITE_BLOCK_SIZE_IN_BYTES; +var DEFAULT_OPERATION_MEMORY_USAGE = Constants.BlobConstants.DEFAULT_WRITE_BLOCK_SIZE_IN_BYTES; var DEFAULT_GLOBAL_CONCURRENCY = 5; //Default http connection limitation for nodejs var SystemTotalMemory = os.totalmem(); -var nodeVersion = utils.getNodeVersion(); +var nodeVersion = azureutil.getNodeVersion(); var enableReuseSocket = nodeVersion.major >= 0 && nodeVersion.minor >= 10; /** @@ -342,7 +342,7 @@ function RestOperation(serviceClient, operation) { this._userCallback = arguments[arguments.length - 1]; this._callbackArguments = null; var sliceEnd = arguments.length; - if(utils.objectIsFunction(this._userCallback)) { + if(azureutil.objectIsFunction(this._userCallback)) { sliceEnd--; } else { this._userCallback = null; @@ -380,7 +380,7 @@ function CommonOperation(operationFunc, callback) { this.operationId = -1; this._callbackArguments = null; var sliceStart = 2; - if(utils.objectIsFunction(callback)) { + if(azureutil.objectIsFunction(callback)) { this._userCallback = callback; } else { this._userCallback = null; diff --git a/lib/services/blob/internal/chunkAllocator.js b/lib/common/streams/chunkallocator.js similarity index 99% rename from lib/services/blob/internal/chunkAllocator.js rename to lib/common/streams/chunkallocator.js index a1e0078b..19729223 100644 --- a/lib/services/blob/internal/chunkAllocator.js +++ b/lib/common/streams/chunkallocator.js @@ -13,8 +13,6 @@ // See the License for the specific language governing permissions and // limitations under the License. // - - /** * Chunked memory pool allocator. * It could dramatically reduce the memory usage. diff --git a/lib/services/blob/internal/chunkStream.js b/lib/common/streams/chunkstream.js similarity index 98% rename from lib/services/blob/internal/chunkStream.js rename to lib/common/streams/chunkstream.js index 8a07a55f..1f4f99d6 100644 --- a/lib/services/blob/internal/chunkStream.js +++ b/lib/common/streams/chunkstream.js @@ -16,11 +16,9 @@ var stream = require('stream'); var crypto = require('crypto'); - -var azureCommon = require('./../../../common/lib/common'); -var Constants = azureCommon.Constants; - var util = require('util'); + +var Constants = require('../util/constants'); var bufferSize = Constants.BlobConstants.DEFAULT_WRITE_BLOCK_SIZE_IN_BYTES; /** diff --git a/lib/services/blob/internal/chunkStreamWithStream.js b/lib/common/streams/chunkstreamwithstream.js similarity index 94% rename from lib/services/blob/internal/chunkStreamWithStream.js rename to lib/common/streams/chunkstreamwithstream.js index a42fa44e..23905278 100644 --- a/lib/services/blob/internal/chunkStreamWithStream.js +++ b/lib/common/streams/chunkstreamwithstream.js @@ -14,7 +14,7 @@ // limitations under the License. // -var ChunkStream = require('./chunkStream'); +var ChunkStream = require('./chunkstream'); var EventEmitter = require('events').EventEmitter; var util = require('util'); @@ -29,9 +29,9 @@ var util = require('util'); function ChunkStreamWithStream(stream, options) { ChunkStream.call(this, options); - stream.pause(); // Pause stream and wait for data listener. It's useful for node v0.6 and v0.8 + stream.pause(); // Pause stream and wait for data listener. It's useful for node v0.8 this._stream = stream; - this._stream.on('end', this.end.bind(this)); // Should catch the end event for node v0.6 and v0.8 + this._stream.on('end', this.end.bind(this)); // Should catch the end event for node v0.8 } util.inherits(ChunkStreamWithStream, ChunkStream); diff --git a/lib/services/blob/internal/filereadstream.js b/lib/common/streams/filereadstream.js similarity index 97% rename from lib/services/blob/internal/filereadstream.js rename to lib/common/streams/filereadstream.js index 9bfd534a..a4492daf 100644 --- a/lib/services/blob/internal/filereadstream.js +++ b/lib/common/streams/filereadstream.js @@ -17,11 +17,10 @@ var fs = require('fs'); var util = require('util'); -var azureCommon = require('./../../../common/lib/common'); -var Constants = azureCommon.Constants; +var Constants = require('../util/constants'); +var bufferSize = Constants.BlobConstants.DEFAULT_WRITE_BLOCK_SIZE_IN_BYTES; var EventEmitter = require('events').EventEmitter; -var bufferSize = Constants.BlobConstants.DEFAULT_WRITE_BLOCK_SIZE_IN_BYTES; /** * File read stream diff --git a/lib/services/blob/internal/speedsummary.js b/lib/common/streams/speedsummary.js similarity index 98% rename from lib/services/blob/internal/speedsummary.js rename to lib/common/streams/speedsummary.js index df840cdf..09fbc80b 100644 --- a/lib/services/blob/internal/speedsummary.js +++ b/lib/common/streams/speedsummary.js @@ -15,9 +15,7 @@ // var util = require('util'); - -var azureCommon = require('./../../../common/lib/common'); -var azureutil = azureCommon.util; +var azureutil = require('../util/util'); /** * Blob upload/download speed summary diff --git a/lib/common/lib/util/constants.js b/lib/common/util/constants.js similarity index 99% rename from lib/common/lib/util/constants.js rename to lib/common/util/constants.js index 69f23a4c..9964f430 100644 --- a/lib/common/lib/util/constants.js +++ b/lib/common/util/constants.js @@ -31,7 +31,7 @@ var Constants = { /* * Specifies the value to use for UserAgent header. */ - USER_AGENT_PRODUCT_VERSION: '0.9', + USER_AGENT_PRODUCT_VERSION: '0.2.1', /** * Constant representing a kilobyte (Non-SI version). diff --git a/lib/common/lib/util/date.js b/lib/common/util/date.js similarity index 100% rename from lib/common/lib/util/date.js rename to lib/common/util/date.js diff --git a/lib/common/lib/util/iso8061date.js b/lib/common/util/iso8061date.js similarity index 100% rename from lib/common/lib/util/iso8061date.js rename to lib/common/util/iso8061date.js diff --git a/lib/common/lib/util/patch-xmlbuilder.js b/lib/common/util/patch-xmlbuilder.js similarity index 100% rename from lib/common/lib/util/patch-xmlbuilder.js rename to lib/common/util/patch-xmlbuilder.js diff --git a/lib/common/lib/util/sr.js b/lib/common/util/sr.js similarity index 100% rename from lib/common/lib/util/sr.js rename to lib/common/util/sr.js diff --git a/lib/common/lib/services/storageutilities.js b/lib/common/util/storageutilities.js similarity index 100% rename from lib/common/lib/services/storageutilities.js rename to lib/common/util/storageutilities.js diff --git a/lib/common/lib/util/util.js b/lib/common/util/util.js similarity index 67% rename from lib/common/lib/util/util.js rename to lib/common/util/util.js index 38f3be89..c31ef1ea 100644 --- a/lib/common/lib/util/util.js +++ b/lib/common/util/util.js @@ -20,7 +20,7 @@ var crypto = require('crypto'); var _ = require('underscore'); var util = require('util'); var Constants = require('./constants'); -var StorageUtilities = require('../services/storageutilities'); +var StorageUtilities = require('./storageutilities'); var SR = require('./sr'); /** @@ -52,21 +52,6 @@ exports.objectKeysLength = function (value) { return _.keys(value).length; }; -/** -* Returns the name of the first property in an object. -* -* @param {object} value The object which key is to be returned. -* @return {number} The name of the first key in the object. -*/ -exports.objectFirstKey = function (value) { - if (value && Object.keys(value).length > 0) { - return Object.keys(value)[0]; - } - - // Object has no properties - return null; -}; - /** * Checks if a value is null or undefined. * @@ -204,72 +189,6 @@ exports.stringEndsWith = function (text, suffix) { return text.substr(text.length - suffix.length) === suffix; }; -/** -* Determines if a string contains an integer number. -* -* @param {string} text The string to assert. -* @return {Bool} True if the string contains an integer number; false otherwise. -*/ -exports.stringIsInt = function (value) { - if (!value) { - return false; - } - - var intValue = parseInt(value, 10); - return intValue.toString().length === value.length && - intValue === parseFloat(value); -}; - -/** -* Determines if a string contains a float number. -* -* @param {string} text The string to assert. -* @return {Bool} True if the string contains a float number; false otherwise. -*/ -exports.stringIsFloat = function (value) { - if (!value) { - return false; - } - - var floatValue = parseFloat(value); - return floatValue.toString().length === value.length && - parseInt(value, 10) !== floatValue; -}; - -/** -* Determines if a string contains a number. -* -* @param {string} text The string to assert. -* @return {Bool} True if the string contains a number; false otherwise. -*/ -exports.stringIsNumber = function (value) { - return !isNaN(value); -}; - -/** -* Determines if a date object is valid. -* -* @param {Date} date The date to test -* @return {Bool} True if the date is valid; false otherwise. -*/ -exports.stringIsDate = function (date) { - if (Object.prototype.toString.call(date) !== '[object Date]') { - return false; - } - - return !isNaN(date.getTime()); -}; - -/** -* Checks if a parsed URL is HTTPS -* -* @param {object} urlToCheck The url to check -* @return {bool} True if the URL is HTTPS; false otherwise. -*/ -exports.urlIsHTTPS = function (urlToCheck) { - return urlToCheck.protocol.toLowerCase() === Constants.HTTPS; -}; - /** * Removes the BOM from a string. * @@ -334,65 +253,6 @@ exports.tryGetValueInsensitive = function (key, haystack, defaultValue) { return defaultValue; }; -function longUnsignedRor(value, count) { - for(var i = 0; i= i ; j--) { - loopValue += data[j] * multiplier; - multiplier = multiplier * 256; - } - - // Converts them into base32 - var bytes = Math.min(data.length - i, 5); - for (var bitOffset = (bytes+1)*8 - 5; bitOffset > 3; bitOffset -= 5) { - var index = longUnsignedRor(loopValue,bitOffset) % 32; - result += base32StandardAlphabet[index]; - } - } - return result; -} - -/** -* Returns the namespace for a subscriptoinId, prefix and location -* -* @subscriptionId {string} The Azure subscription id. -* @prefix {string} The prifix for the service. -* @location {string} The location of the service. -* @return {Bool} True if the value is an integer number; false otherwise. -*/ -exports.getNameSpace = function (subscriptionId, prefix, location) { - location = location.replace(/ /g, '-'); - var hash = crypto.createHash('sha256').update(new Buffer(subscriptionId, 'utf-8')).digest('hex'); - return prefix + base32NoPaddingEncode(new Buffer(hash, 'hex')) + '-' + location; -}; - -/** -* Determines if a value (string or number) is an integer number. -* -* @param {object} The value to assess. -* @return {Bool} True if the value is an integer number; false otherwise. -*/ -exports.isInt = function (value){ - if((parseFloat(value) == parseInt(value, 10)) && !isNaN(value)) { - return true; - } - else { - return false; - } -}; - /** * Returns the value in a chained object. * @@ -486,42 +346,6 @@ exports.isBufferAllZero = function (buffer) { return true; }; -/** -* Write zero to stream -*/ -var zeroBuffer = null; -exports.writeZeroToStream = function(stream, length, md5Hash, progressCallback, callback) { - var defaultBufferSize = Constants.BlobConstants.DEFAULT_WRITE_BLOCK_SIZE_IN_BYTES; - var bufferSize = Math.min(defaultBufferSize, length); - var remaining = length - bufferSize; - var buffer = null; - if(bufferSize == defaultBufferSize) { - if(!zeroBuffer) { - zeroBuffer = new Buffer(defaultBufferSize); - zeroBuffer.fill(0); - } - buffer = zeroBuffer; - } else { - buffer = new Buffer(bufferSize); - buffer.fill(0); - } - if(md5Hash) { - md5Hash.update(buffer); - } - //We can only write the entire buffer to stream instead of part of buffer. - return stream.write(buffer, function() { - if (exports.objectIsFunction(progressCallback)) { - progressCallback(null, buffer.length); - } - buffer = null; - if (remaining > 0) { - exports.writeZeroToStream(stream, remaining, md5Hash, progressCallback, callback); - } else if (exports.objectIsFunction(callback)) { - callback(null, null); - } - }); -}; - /** * Calculate md5sum for the content */ diff --git a/lib/common/lib/util/validate.js b/lib/common/util/validate.js similarity index 100% rename from lib/common/lib/util/validate.js rename to lib/common/util/validate.js diff --git a/lib/services/blob/blobservice.js b/lib/services/blob/blobservice.js index 1b7f3e1a..a963f2c8 100644 --- a/lib/services/blob/blobservice.js +++ b/lib/services/blob/blobservice.js @@ -24,27 +24,28 @@ var _ = require('underscore'); var crypto = require('crypto'); var extend = require('extend'); -var FileReadStream = require('./internal/filereadstream'); -var BatchOperation = require('./internal/batchoperation'); -var SpeedSummary = require('./internal/speedsummary'); -var ChunkAllocator = require('./internal/chunkAllocator'); - -var ChunkStream = require('./internal/chunkStream'); -var ChunkStreamWithStream = require('./internal/chunkStreamWithStream'); - -var azureCommon = require('./../../common/lib/common'); +var azureCommon = require('./../../common/common'); var azureutil = azureCommon.util; var SR = azureCommon.SR; var validate = azureCommon.validate; -var SR = azureCommon.SR; var StorageServiceClient = azureCommon.StorageServiceClient; var WebResource = azureCommon.WebResource; + +// Constants var Constants = azureCommon.Constants; var BlobConstants = Constants.BlobConstants; var HeaderConstants = Constants.HeaderConstants; var QueryStringConstants = Constants.QueryStringConstants; var RequestLocationMode = Constants.RequestLocationMode; +// Streams +var BatchOperation = azureCommon.BatchOperation; +var SpeedSummary = azureCommon.SpeedSummary; +var ChunkAllocator = azureCommon.ChunkAllocator; +var ChunkStream = azureCommon.ChunkStream; +var ChunkStreamWithStream = azureCommon.ChunkStreamWithStream; +var FileReadStream = azureCommon.FileReadStream; + // Models requires var ServicePropertiesResult = azureCommon.ServicePropertiesResult; var AclResult = azureCommon.AclResult; diff --git a/lib/services/blob/blobutilities.js b/lib/services/blob/blobutilities.js index 9a626a0e..69e8c681 100644 --- a/lib/services/blob/blobutilities.js +++ b/lib/services/blob/blobutilities.js @@ -13,7 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. // -var azureCommon = require('./../../common/lib/common'); +var azureCommon = require('./../../common/common'); var HeaderConstants = azureCommon.Constants.HeaderConstants; // Expose 'BlobUtilities'. @@ -63,7 +63,7 @@ var BlobUtilities = { BlobListingDetails: { SNAPSHOTS: 'snapshots', METADATA: 'metadata', - UNCOMMITTEDBLOBS: 'uncommittedblobs' + UNCOMMITTED_BLOBS: 'uncommittedblobs' }, /** diff --git a/lib/services/blob/models/blobresult.js b/lib/services/blob/models/blobresult.js index d62b2a49..c886ea18 100644 --- a/lib/services/blob/models/blobresult.js +++ b/lib/services/blob/models/blobresult.js @@ -17,7 +17,7 @@ // Module dependencies. var _ = require('underscore'); -var azureCommon = require('./../../../common/lib/common'); +var azureCommon = require('./../../../common/common'); var azureutil = azureCommon.util; var Constants = azureCommon.Constants; var HeaderConstants = Constants.HeaderConstants; diff --git a/lib/services/blob/models/blocklistresult.js b/lib/services/blob/models/blocklistresult.js index 13ce4d94..5e2a1087 100644 --- a/lib/services/blob/models/blocklistresult.js +++ b/lib/services/blob/models/blocklistresult.js @@ -15,7 +15,7 @@ // // Module dependencies. -var azureCommon = require('./../../../common/lib/common'); +var azureCommon = require('./../../../common/common'); var xmlbuilder = azureCommon.xmlbuilder; var Constants = azureCommon.Constants; diff --git a/lib/services/blob/models/containerresult.js b/lib/services/blob/models/containerresult.js index 1127633a..d7a9a25b 100644 --- a/lib/services/blob/models/containerresult.js +++ b/lib/services/blob/models/containerresult.js @@ -15,7 +15,7 @@ // // Module dependencies. -var Constants = require('./../../../common/lib/common').Constants; +var Constants = require('./../../../common/common').Constants; var HeaderConstants = Constants.HeaderConstants; var BlobUtilities = require('../blobutilities'); diff --git a/lib/services/blob/models/leaseresult.js b/lib/services/blob/models/leaseresult.js index 96f4ff06..372d64a6 100644 --- a/lib/services/blob/models/leaseresult.js +++ b/lib/services/blob/models/leaseresult.js @@ -15,7 +15,7 @@ // // Module dependencies. -var Constants = require('./../../../common/lib/common').Constants; +var Constants = require('./../../../common/common').Constants; var HeaderConstants = Constants.HeaderConstants; function LeaseResult(container, blob, id, time) { diff --git a/lib/services/queue/models/queuemessageresult.js b/lib/services/queue/models/queuemessageresult.js index 24dbbef2..ec3d96b3 100644 --- a/lib/services/queue/models/queuemessageresult.js +++ b/lib/services/queue/models/queuemessageresult.js @@ -15,7 +15,7 @@ // // Module dependencies. -var azureCommon = require('./../../../common/lib/common'); +var azureCommon = require('./../../../common/common'); var xmlbuilder = azureCommon.xmlbuilder; var Constants = azureCommon.Constants; diff --git a/lib/services/queue/models/queueresult.js b/lib/services/queue/models/queueresult.js index d7daf098..9b35ba34 100644 --- a/lib/services/queue/models/queueresult.js +++ b/lib/services/queue/models/queueresult.js @@ -15,7 +15,7 @@ // // Module dependencies. -var Constants = require('./../../../common/lib/common').Constants; +var Constants = require('./../../../common/common').Constants; var HeaderConstants = Constants.HeaderConstants; function QueueResult(name, metadata) { diff --git a/lib/services/queue/queueservice.js b/lib/services/queue/queueservice.js index becd321b..96ae16b2 100644 --- a/lib/services/queue/queueservice.js +++ b/lib/services/queue/queueservice.js @@ -19,7 +19,7 @@ var util = require('util'); var _ = require('underscore'); var extend = require('extend'); -var azureCommon = require('./../../common/lib/common'); +var azureCommon = require('./../../common/common'); var azureutil = azureCommon.util; var SR = azureCommon.SR; var validate = azureCommon.validate; diff --git a/lib/services/table/internal/edmhandler.js b/lib/services/table/internal/edmhandler.js index aab90bfb..b0b92346 100644 --- a/lib/services/table/internal/edmhandler.js +++ b/lib/services/table/internal/edmhandler.js @@ -18,7 +18,7 @@ var _ = require('underscore'); var util = require('util'); var guid = require('node-uuid'); -var azureCommon = require('./../../../common/lib/common'); +var azureCommon = require('./../../../common/common'); var azureutil = azureCommon.util; var SR = azureCommon.SR; diff --git a/lib/services/table/internal/odatahandler.js b/lib/services/table/internal/odatahandler.js index d500f6e9..591acf0b 100644 --- a/lib/services/table/internal/odatahandler.js +++ b/lib/services/table/internal/odatahandler.js @@ -17,7 +17,7 @@ // Module dependencies. var util = require('util'); -var azureCommon = require('./../../../common/lib/common'); +var azureCommon = require('./../../../common/common'); var azureutil = azureCommon.util; var SR = azureCommon.SR; var Constants = azureCommon.Constants; diff --git a/lib/services/table/internal/requesthandler.js b/lib/services/table/internal/requesthandler.js new file mode 100644 index 00000000..fae73b8c --- /dev/null +++ b/lib/services/table/internal/requesthandler.js @@ -0,0 +1,117 @@ +// +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +var azureCommon = require('./../../../common/common'); + +var WebResource = azureCommon.WebResource; +var SR = azureCommon.SR; +var Constants = azureCommon.Constants; +var HeaderConstants = Constants.HeaderConstants; +var TableConstants = Constants.TableConstants; + +var entityResult = require('../models/entityresult'); + +exports = module.exports; + +/** +* Retrieves the entity path from the table name and an entity descriptor. +* @ignore +* +* @param {string} table The table name. +* @param {object} entity The entity descriptor. +* @return {string} The entity path. +*/ +function getEntityPath (tableName, partitionKey, rowKey) { + var path = '/' + tableName; + + if (typeof(partitionKey) === 'string' && typeof(rowKey) === 'string') { + path = path + '(PartitionKey=\'' + encodeURIComponent(partitionKey.toString('utf8')) + '\',RowKey=\'' + encodeURIComponent(rowKey.toString('utf8')) + '\')'; + } else { + throw new Error(SR. INCORRECT_ENTITY_KEYS); + } + + return path; +} + +/** +* Constructs the web resource for a table operation. +* +* @param {string} operation The operation to perform. +* @param {string} table The table name. +* @param {object} entityDescriptor The entity descriptor. +* @param {object} [options] The create options or callback function. +* @param {boolean} [options.checkEtag] Boolean value indicating weather the etag should be matched or not. +* @param {string} [options.echoContent] Whether or not to return the entity upon a successful insert. Default to false. +* @param {string} [options.payloadFormat] The payload format to use for the request. +* @param {LocationMode} [options.locationMode] Specifies the location mode used to decide which location the request should be sent to. +* Please see StorageUtilities.LocationMode for the possible values. +* @param {int} [options.timeoutIntervalInMs] The server timeout interval, in milliseconds, to use for the request. +* @param {int} [options.maximumExecutionTimeInMs] The maximum execution time, in milliseconds, across all potential retries, to use when making this request. +* The maximum execution time interval begins at the time that the client begins building the request. The maximum +* execution time is checked intermittently while performing requests, and before executing retries. +* @return {webResource} +*/ +exports.constructEntityWebResource = function (operation, table, entityDescriptor, options) { + var webResource = null; + if (operation === TableConstants.Operations.INSERT) { + webResource = WebResource.post(table) + .withHeader(HeaderConstants.PREFER, options.echoContent ? HeaderConstants.PREFER_CONTENT : HeaderConstants.PREFER_NO_CONTENT); + } else { + var path = getEntityPath(table, entityDescriptor.PartitionKey[TableConstants.ODATA_VALUE_MARKER], entityDescriptor.RowKey[TableConstants.ODATA_VALUE_MARKER]); + + if (operation === TableConstants.Operations.DELETE) { + webResource = WebResource.del(path); + } else if (operation === TableConstants.Operations.MERGE || operation === TableConstants.Operations.INSERT_OR_MERGE) { + webResource = WebResource.merge(path); + } else if (operation === TableConstants.Operations.UPDATE || operation === TableConstants.Operations.INSERT_OR_REPLACE) { + webResource = WebResource.put(path); + } else if (operation === TableConstants.Operations.RETRIEVE) { + webResource = WebResource.get(path); + } else { + throw new Error(util.format(SR.INVALID_TABLE_OPERATION, operation)); + } + } + + if (operation === TableConstants.Operations.DELETE || operation === TableConstants.Operations.UPDATE || operation === TableConstants.Operations.MERGE) { + webResource.withHeader(HeaderConstants.IF_MATCH, entityResult.getEtag(entityDescriptor) || '*'); + } + + var entitySerializedDescriptor; + if (!(operation === TableConstants.Operations.DELETE || operation === TableConstants.Operations.RETRIEVE)) { + entitySerializedDescriptor = entityResult.serialize(entityDescriptor); + } + + exports.setTableRequestHeadersAndBody(webResource, entitySerializedDescriptor, options.payloadFormat); + + return webResource; +}; + +/** +* Sets the table request headers. +* +* @param {string} webResource The webResource to add headers to. +* @param {object} [body] The body of the request. +* @return {undefined} +*/ +exports.setTableRequestHeadersAndBody = function (webResource, body, acceptType) { + if (body) { + webResource.withHeader(HeaderConstants.CONTENT_LENGTH, Buffer.byteLength(body, 'utf8')) + .withBody(body) + .withHeader(HeaderConstants.CONTENT_TYPE, HeaderConstants.JSON_CONTENT_TYPE_VALUE); + } + + webResource.withHeader(HeaderConstants.ACCEPT_HEADER, acceptType) + .withHeader(HeaderConstants.MAX_DATA_SERVICE_VERSION, TableConstants.DEFAULT_DATA_SERVICE_VERSION); +}; \ No newline at end of file diff --git a/lib/services/table/internal/sharedkeytable.js b/lib/services/table/internal/sharedkeytable.js index 42cb4814..f65da7a6 100644 --- a/lib/services/table/internal/sharedkeytable.js +++ b/lib/services/table/internal/sharedkeytable.js @@ -16,7 +16,7 @@ // Module dependencies. var util = require('util'); -var azureCommon = require('./../../../common/lib/common'); +var azureCommon = require('./../../../common/common'); var SharedKey = azureCommon.SharedKey; var azureutil = azureCommon.util; var Constants = azureCommon.Constants; diff --git a/lib/services/table/models/batchresult.js b/lib/services/table/models/batchresult.js index e99029f2..3662e12d 100644 --- a/lib/services/table/models/batchresult.js +++ b/lib/services/table/models/batchresult.js @@ -17,14 +17,14 @@ // Module dependencies. var crypto = require('crypto'); -var azureCommon = require('./../../../common/lib/common'); +var azureCommon = require('./../../../common/common'); var StorageServiceClient = azureCommon.StorageServiceClient; var WebResource = azureCommon.WebResource; var Constants = azureCommon.Constants; var HeaderConstants = Constants.HeaderConstants; var TableConstants = Constants.TableConstants; -var TableService = require('../TableService'); +var RequestHandler = require('../internal/requesthandler'); var entityResult = require('./entityresult'); /** @@ -110,7 +110,7 @@ BatchResult.prototype.serialize = function () { */ BatchResult.prototype._serializeOperation = function (operation, count) { operation.options.payloadFormat = operation.options.payloadFormat || this.tableService.defaultPayloadFormat; - var webResource = TableService._constructEntityWebResource(operation.type, this.table, operation.entity, operation.options); + var webResource = RequestHandler.constructEntityWebResource(operation.type, this.table, operation.entity, operation.options); if (count) { webResource.headers[HeaderConstants.CONTENT_ID] = count; diff --git a/lib/services/table/models/entityresult.js b/lib/services/table/models/entityresult.js index 7579314c..1b4b883d 100644 --- a/lib/services/table/models/entityresult.js +++ b/lib/services/table/models/entityresult.js @@ -15,7 +15,7 @@ // // Module dependencies. -var azureCommon = require('./../../../common/lib/common'); +var azureCommon = require('./../../../common/common'); var Constants = azureCommon.Constants; var TableConstants = Constants.TableConstants; var HeaderConstants = Constants.HeaderConstants; diff --git a/lib/services/table/tablebatch.js b/lib/services/table/tablebatch.js index 09613fba..77133dc2 100644 --- a/lib/services/table/tablebatch.js +++ b/lib/services/table/tablebatch.js @@ -17,7 +17,7 @@ // Module dependencies. var extend = require('extend'); -var azureCommon = require('./../../common/lib/common'); +var azureCommon = require('./../../common/common'); var SR = azureCommon.SR; var validate = azureCommon.validate; var Constants = azureCommon.Constants; diff --git a/lib/services/table/tablequery.js b/lib/services/table/tablequery.js index 974a0a58..c4224dad 100644 --- a/lib/services/table/tablequery.js +++ b/lib/services/table/tablequery.js @@ -18,7 +18,7 @@ var _ = require('underscore'); var util = require('util'); -var azureCommon = require('./../../common/lib/common'); +var azureCommon = require('./../../common/common'); var azureutil = azureCommon.util; var SR = azureCommon.SR; var QueryStringConstants = azureCommon.Constants.QueryStringConstants; diff --git a/lib/services/table/tableservice.js b/lib/services/table/tableservice.js index b4acbcd3..9ea72f88 100644 --- a/lib/services/table/tableservice.js +++ b/lib/services/table/tableservice.js @@ -19,12 +19,13 @@ var util = require('util'); var extend = require('extend'); var _ = require('underscore'); -var azureCommon = require('./../../common/lib/common'); +var azureCommon = require('./../../common/common'); var azureutil = azureCommon.util; var validate = azureCommon.validate; var SR = azureCommon.SR; var StorageServiceClient = azureCommon.StorageServiceClient; var SharedKeyTable = require('./internal/sharedkeytable'); +var RequestHandler = require('./internal/requesthandler'); var TableQuery = require('./tablequery'); var WebResource = azureCommon.WebResource; var Constants = azureCommon.Constants; @@ -90,26 +91,6 @@ function TableService(storageAccountOrConnectionString, storageAccessKey, host, util.inherits(TableService, StorageServiceClient); -/** -* Retrieves the entity path from the table name and an entity descriptor. -* @ignore -* -* @param {string} table The table name. -* @param {object} entity The entity descriptor. -* @return {string} The entity path. -*/ -function getEntityPath (tableName, partitionKey, rowKey) { - var path = '/' + tableName; - - if (typeof(partitionKey) === 'string' && typeof(rowKey) === 'string') { - path = path + '(PartitionKey=\'' + encodeURIComponent(partitionKey.toString('utf8')) + '\',RowKey=\'' + encodeURIComponent(rowKey.toString('utf8')) + '\')'; - } else { - throw new Error(SR. INCORRECT_ENTITY_KEYS); - } - - return path; -} - // Table service methods /** @@ -312,7 +293,7 @@ TableService.prototype.listTablesSegmentedWithPrefix = function (prefix, current options.payloadFormat = options.payloadFormat || this.defaultPayloadFormat; var webResource = WebResource.get(TableConstants.TABLE_SERVICE_TABLE_NAME); - TableService._setTableRequestHeadersAndBody(webResource, null, options.payloadFormat); + RequestHandler.setTableRequestHeadersAndBody(webResource, null, options.payloadFormat); if(!azureutil.objectIsNull(currentToken)) { webResource.withQueryOption(TableConstants.NEXT_TABLE_NAME, currentToken.nextTableName); @@ -586,7 +567,7 @@ TableService.prototype.createTable = function (table, optionsOrCallback, callbac var webResource = WebResource.post('Tables') .withHeader(HeaderConstants.PREFER, HeaderConstants.PREFER_NO_CONTENT); - TableService._setTableRequestHeadersAndBody(webResource, tableDescriptor); + RequestHandler.setTableRequestHeadersAndBody(webResource, tableDescriptor); var processResponseCallback = function (responseObject, next) { responseObject.tableResponse = null; @@ -694,7 +675,7 @@ TableService.prototype.deleteTable = function (table, optionsOrCallback, callbac var options = extend(true, {}, userOptions); var webResource = WebResource.del('Tables(\'' + table + '\')'); - TableService._setTableRequestHeadersAndBody(webResource); + RequestHandler.setTableRequestHeadersAndBody(webResource); var processResponseCallback = function (responseObject, next) { var finalCallback = function (returnObject) { @@ -858,7 +839,7 @@ TableService.prototype.queryEntities = function (table, tableQuery, currentToken options.payloadFormat = options.payloadFormat || this.defaultPayloadFormat; var webResource = WebResource.get(table); - TableService._setTableRequestHeadersAndBody(webResource, null, options.payloadFormat); + RequestHandler.setTableRequestHeadersAndBody(webResource, null, options.payloadFormat); if (tableQuery) { var queryString = tableQuery.toQueryObject(); @@ -1205,7 +1186,7 @@ TableService.prototype._doesTableExist = function (table, primaryOnly, optionsOr } var webResource = WebResource.get('Tables(\'' + table + '\')'); - TableService._setTableRequestHeadersAndBody(webResource); + RequestHandler.setTableRequestHeadersAndBody(webResource); var processResponseCallback = function (responseObject, next) { if(!responseObject.error){ @@ -1266,7 +1247,7 @@ TableService.prototype._performEntityOperation = function (operation, table, ent var options = extend(true, {}, userOptions); options.payloadFormat = options.payloadFormat || this.defaultPayloadFormat; - var webResource = TableService._constructEntityWebResource(operation, table, entityDescriptor, options); + var webResource = RequestHandler.constructEntityWebResource(operation, table, entityDescriptor, options); var processResponseCallback = function (responseObject, next) { var finalCallback; @@ -1291,81 +1272,6 @@ TableService.prototype._performEntityOperation = function (operation, table, ent this.performRequest(webResource, webResource.body, options, processResponseCallback); }; -/** -* Constructs the web resource for a table operation. -* -* @this {TableService} -* @param {string} operation The operation to perform. -* @param {string} table The table name. -* @param {object} entityDescriptor The entity descriptor. -* @param {object} [options] The create options or callback function. -* @param {boolean} [options.checkEtag] Boolean value indicating weather the etag should be matched or not. -* @param {string} [options.echoContent] Whether or not to return the entity upon a successful insert. Default to false. -* @param {string} [options.payloadFormat] The payload format to use for the request. -* @param {LocationMode} [options.locationMode] Specifies the location mode used to decide which location the request should be sent to. -* Please see StorageUtilities.LocationMode for the possible values. -* @param {int} [options.timeoutIntervalInMs] The server timeout interval, in milliseconds, to use for the request. -* @param {int} [options.maximumExecutionTimeInMs] The maximum execution time, in milliseconds, across all potential retries, to use when making this request. -* The maximum execution time interval begins at the time that the client begins building the request. The maximum -* execution time is checked intermittently while performing requests, and before executing retries. -* @return {webResource} -* @ignore -*/ -TableService._constructEntityWebResource = function (operation, table, entityDescriptor, options) { - var webResource = null; - if (operation === TableConstants.Operations.INSERT) { - webResource = WebResource.post(table) - .withHeader(HeaderConstants.PREFER, options.echoContent ? HeaderConstants.PREFER_CONTENT : HeaderConstants.PREFER_NO_CONTENT); - } else { - var path = getEntityPath(table, entityDescriptor.PartitionKey[TableConstants.ODATA_VALUE_MARKER], entityDescriptor.RowKey[TableConstants.ODATA_VALUE_MARKER]); - - if (operation === TableConstants.Operations.DELETE) { - webResource = WebResource.del(path); - } else if (operation === TableConstants.Operations.MERGE || operation === TableConstants.Operations.INSERT_OR_MERGE) { - webResource = WebResource.merge(path); - } else if (operation === TableConstants.Operations.UPDATE || operation === TableConstants.Operations.INSERT_OR_REPLACE) { - webResource = WebResource.put(path); - } else if (operation === TableConstants.Operations.RETRIEVE) { - webResource = WebResource.get(path); - } else { - throw new Error(util.format(SR.INVALID_TABLE_OPERATION, operation)); - } - } - - if (operation === TableConstants.Operations.DELETE || operation === TableConstants.Operations.UPDATE || operation === TableConstants.Operations.MERGE) { - webResource.withHeader(HeaderConstants.IF_MATCH, entityResult.getEtag(entityDescriptor) || '*'); - } - - var entitySerializedDescriptor; - if (!(operation === TableConstants.Operations.DELETE || operation === TableConstants.Operations.RETRIEVE)) { - entitySerializedDescriptor = entityResult.serialize(entityDescriptor); - } - - TableService._setTableRequestHeadersAndBody(webResource, entitySerializedDescriptor, options.payloadFormat); - - return webResource; -}; - -/** -* Sets the table request headers. -* -* @this {TableService} -* @param {string} webResource The webResource to add headers to. -* @param {object} [body] The body of the request. -* @return {undefined} -* @ignore -*/ -TableService._setTableRequestHeadersAndBody = function (webResource, body, acceptType) { - if (body) { - webResource.withHeader(HeaderConstants.CONTENT_LENGTH, Buffer.byteLength(body, 'utf8')) - .withBody(body) - .withHeader(HeaderConstants.CONTENT_TYPE, HeaderConstants.JSON_CONTENT_TYPE_VALUE); - } - - webResource.withHeader(HeaderConstants.ACCEPT_HEADER, acceptType) - .withHeader(HeaderConstants.MAX_DATA_SERVICE_VERSION, TableConstants.DEFAULT_DATA_SERVICE_VERSION); -}; - /** * Given the partition key, row key, property name, property value, * and the property Edm type if given by the service, returns the Edm type of the property. diff --git a/package.json b/package.json index 399a1a70..232a826b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "azure-storage", "author": "Microsoft Corporation", - "version": "0.2.0", + "version": "0.2.1", "description": "Microsoft Azure Storage Client Library for Node.js", "tags": [ "azure", diff --git a/test/common/connectionstringparsertests.js b/test/common/connectionstringparsertests.js index ae10d497..81dfb5cb 100644 --- a/test/common/connectionstringparsertests.js +++ b/test/common/connectionstringparsertests.js @@ -20,9 +20,9 @@ var util = require('util'); // Test includes var testutil = require('../framework/util'); -var azure = testutil.libRequire('azure-storage'); -var ServiceSettings = azure.ServiceSettings; +var ServiceSettings = testutil.libRequire('common/services/servicesettings'); +var azure = testutil.libRequire('azure-storage'); var Constants = azure.Constants; var ConnectionStringKeys = Constants.ConnectionStringKeys; var SR = azure.SR; diff --git a/test/common/filters/exponentialretrypolicyfilter-tests.js b/test/common/filters/exponentialretrypolicyfilter-tests.js index e2b67d3c..7e5c1441 100644 --- a/test/common/filters/exponentialretrypolicyfilter-tests.js +++ b/test/common/filters/exponentialretrypolicyfilter-tests.js @@ -41,10 +41,9 @@ describe('exponentialretrypolicyfilter-tests', function () { }); afterEach(function (done) { - tableService.deleteTableIfExists(tableName, function(deleteError) { - if(!deleteError) { - done(); - } + tableService.deleteTableIfExists(tableName, function (deleteError) { + assert.equal(deleteError, null); + done(); }); }); diff --git a/test/common/secondarytests.js b/test/common/secondarytests.js index 7d187028..eed3ca4d 100644 --- a/test/common/secondarytests.js +++ b/test/common/secondarytests.js @@ -22,7 +22,7 @@ var testutil = require('../framework/util'); var azure = testutil.libRequire('azure-storage'); var Constants = azure.Constants; var StorageUtilities = azure.StorageUtilities; -var SR = testutil.libRequire('common/lib/util/sr'); +var SR = testutil.libRequire('common/util/sr'); var RetryPolicyFilter = azure.RetryPolicyFilter; var hostName = process.env['AZURE_STORAGE_ACCOUNT']; diff --git a/test/common/servicesettingstests.js b/test/common/servicesettingstests.js index d7f48c46..3ba65bb6 100644 --- a/test/common/servicesettingstests.js +++ b/test/common/servicesettingstests.js @@ -18,8 +18,7 @@ var should = require('should'); var assert = require('assert'); var testutil = require('../framework/util'); -var azure = testutil.libRequire('azure-storage'); -var ServiceSettings = azure.ServiceSettings; +var ServiceSettings = testutil.libRequire('common/services/servicesettings'); describe('ServiceSettingsTests', function () { diff --git a/test/common/sharedkey-tests.js b/test/common/sharedkey-tests.js index 58ea72de..1574351c 100644 --- a/test/common/sharedkey-tests.js +++ b/test/common/sharedkey-tests.js @@ -27,11 +27,13 @@ var StorageServiceClientConstants = Constants.StorageServiceClientConstants; var QueryStringConstants = Constants.QueryStringConstants; var HeaderConstants = Constants.HeaderConstants; +var SharedKey = testutil.libRequire('common/signing/sharedkey'); + var sharedkey; describe('sharedkey-tests', function () { before(function (done) { - sharedkey = new azure.SharedKey(StorageServiceClientConstants.DEVSTORE_STORAGE_ACCOUNT, StorageServiceClientConstants.DEVSTORE_STORAGE_ACCESS_KEY, false); + sharedkey = new SharedKey(StorageServiceClientConstants.DEVSTORE_STORAGE_ACCOUNT, StorageServiceClientConstants.DEVSTORE_STORAGE_ACCESS_KEY, false); done(); }); diff --git a/test/common/storageserviceclienttests.js b/test/common/storageserviceclienttests.js index 31e65e7e..37e9d076 100644 --- a/test/common/storageserviceclienttests.js +++ b/test/common/storageserviceclienttests.js @@ -18,7 +18,7 @@ var should = require('should'); var assert = require('assert'); var testutil = require('../framework/util'); -var HmacSha256Sign = testutil.libRequire('common/lib/services/hmacsha256sign'); +var HmacSha256Sign = testutil.libRequire('common/signing/hmacsha256sign'); var azure = testutil.libRequire('azure-storage'); var StorageServiceClient = azure.StorageServiceClient; diff --git a/test/common/storageservicesettingstests.js b/test/common/storageservicesettingstests.js index cca451cd..6a71f3a3 100644 --- a/test/common/storageservicesettingstests.js +++ b/test/common/storageservicesettingstests.js @@ -23,7 +23,7 @@ var azure = testutil.libRequire('azure-storage'); var Constants = azure.Constants; var StorageServiceClientConstants = Constants.StorageServiceClientConstants; var ConnectionStringKeys = Constants.ConnectionStringKeys; -var StorageServiceSettings = azure.StorageServiceSettings; +var StorageServiceSettings = testutil.libRequire('common/services/storageservicesettings'); describe('StorageServiceSettingsTests', function(done) { diff --git a/test/common/util/iso8061date-tests.js b/test/common/util/iso8061date-tests.js index 76149777..dbc0cafa 100644 --- a/test/common/util/iso8061date-tests.js +++ b/test/common/util/iso8061date-tests.js @@ -20,7 +20,7 @@ var assert = require('assert'); var testutil = require('../../framework/util'); // Lib includes -var ISO8061Date = testutil.libRequire('common/lib/util/iso8061date'); +var ISO8061Date = testutil.libRequire('common/util/iso8061date'); describe('iso8061date-tests', function () { it('parse should work', function (done) { diff --git a/test/common/util/util-tests.js b/test/common/util/util-tests.js index 1bccf272..45d5ccad 100644 --- a/test/common/util/util-tests.js +++ b/test/common/util/util-tests.js @@ -20,7 +20,7 @@ var assert = require('assert'); var testutil = require('../../framework/util'); // Lib includes -var util = testutil.libRequire('common/lib/util/util'); +var util = testutil.libRequire('common/util/util'); describe('util-tests', function() { it('should be an empty object', function (done) { @@ -72,82 +72,6 @@ describe('util-tests', function() { done(); }); - it('should be int', function (done) { - // positives - assert.equal(util.stringIsInt('1'), true); - assert.equal(util.stringIsInt('1asd'), false); - assert.equal(util.stringIsInt('asd1'), false); - assert.equal(util.stringIsInt('1.23'), false); - - // negatives - assert.equal(util.stringIsInt('-1'), true); - assert.equal(util.stringIsInt('-1asd'), false); - assert.equal(util.stringIsInt('-asd1'), false); - assert.equal(util.stringIsInt('-1.23'), false); - - // nulls - assert.equal(util.stringIsInt(null), false); - assert.equal(util.stringIsInt(), false); - - done(); - }); - - it('should be float', function (done) { - // positives - assert.equal(util.stringIsFloat('1'), false); - assert.equal(util.stringIsFloat('1.'), false); - assert.equal(util.stringIsFloat('1.0'), false); - assert.equal(util.stringIsFloat('1.1'), true); - assert.equal(util.stringIsFloat('1.0a'), false); - assert.equal(util.stringIsFloat('1a'), false); - - // negatives - assert.equal(util.stringIsFloat('-1'), false); - assert.equal(util.stringIsFloat('-1.'), false); - assert.equal(util.stringIsFloat('-1.0'), false); - assert.equal(util.stringIsFloat('-1.1'), true); - assert.equal(util.stringIsFloat('-1.0a'), false); - assert.equal(util.stringIsFloat('-1a'), false); - - // nulls - assert.equal(util.stringIsFloat(null), false); - assert.equal(util.stringIsFloat(), false); - - done(); - }); - - it('should be a number', function (done) { - // int positives - assert.equal(util.stringIsNumber('1'), true); - assert.equal(util.stringIsNumber('1asd'), false); - assert.equal(util.stringIsNumber('asd1'), false); - - // int negatives - assert.equal(util.stringIsNumber('-1'), true); - assert.equal(util.stringIsNumber('-1asd'), false); - assert.equal(util.stringIsNumber('-asd1'), false); - - // float positives - assert.equal(util.stringIsNumber('1.'), true); - assert.equal(util.stringIsNumber('1.0'), true); - assert.equal(util.stringIsNumber('1.1'), true); - assert.equal(util.stringIsNumber('1.0a'), false); - assert.equal(util.stringIsNumber('1a'), false); - - // float negatives - assert.equal(util.stringIsNumber('-1.'), true); - assert.equal(util.stringIsNumber('-1.0'), true); - assert.equal(util.stringIsNumber('-1.1'), true); - assert.equal(util.stringIsNumber('-1.0a'), false); - assert.equal(util.stringIsNumber('-1a'), false); - - // nulls - assert.equal(util.stringIsFloat(null), false); - assert.equal(util.stringIsFloat(), false); - - done(); - }); - it('keys counting works', function (done) { // int positives assert.equal(util.objectKeysLength({ }), 0); @@ -158,16 +82,6 @@ describe('util-tests', function() { done(); }); - it('first key works', function (done) { - // int positives - assert.equal(util.objectFirstKey({}), null); - assert.equal(util.objectFirstKey(null), null); - assert.equal(util.objectFirstKey({ prop1: 1 }), 'prop1'); - assert.equal(util.objectFirstKey({ prop1: 1, prop2: 2 }), 'prop1'); - - done(); - }); - it('In array case insensitive', function (done) { // int positives assert.ok(util.inArrayInsensitive('a', [ 'a', 'b', 'c'])); diff --git a/test/common/util/validate-tests.js b/test/common/util/validate-tests.js index c0fafa2b..e0e561ab 100644 --- a/test/common/util/validate-tests.js +++ b/test/common/util/validate-tests.js @@ -17,8 +17,7 @@ var should = require('should'); var testutil = require('../../framework/util'); -var azure = testutil.libRequire('azure-storage'); -var Validate = azure.Validate; +var Validate = testutil.libRequire('common/util/validate'); describe('servicesettings-tests', function () { describe('isValidUri', function () { diff --git a/test/services/blob/blobservice-container-tests.js b/test/services/blob/blobservice-container-tests.js index 15413919..fcded49f 100644 --- a/test/services/blob/blobservice-container-tests.js +++ b/test/services/blob/blobservice-container-tests.js @@ -18,7 +18,7 @@ var guid = require('node-uuid'); // Lib includes var testutil = require('../../framework/util'); -var SR = testutil.libRequire('common/lib/util/sr'); +var SR = testutil.libRequire('common/util/sr'); var azure = testutil.libRequire('azure-storage'); diff --git a/test/services/blob/blobservice-tests.js b/test/services/blob/blobservice-tests.js index f5c8a673..f9689f52 100644 --- a/test/services/blob/blobservice-tests.js +++ b/test/services/blob/blobservice-tests.js @@ -29,10 +29,10 @@ var request = require('request'); var testutil = require('../../framework/util'); // Lib includes -var azureutil = testutil.libRequire('common/lib/util/util'); +var azureutil = testutil.libRequire('common/util/util'); var azure = testutil.libRequire('azure-storage'); -var WebResource = testutil.libRequire('common/lib/http/webresource'); -var SR = testutil.libRequire('common/lib/util/sr'); +var WebResource = azure.WebResource; +var SR = azure.SR; var SharedAccessSignature = azure.SharedAccessSignature; var BlobService = azure.BlobService; var ServiceClient = azure.ServiceClient; @@ -1149,7 +1149,6 @@ describe('BlobService', function () { var sharedAccessPolicy = { AccessPolicy: { Permissions: BlobUtilities.SharedAccessPermissions.READ, - Start: startDate, Expiry: expiryDate } }; @@ -1202,7 +1201,6 @@ describe('BlobService', function () { var sharedAccessPolicy = { AccessPolicy: { Permissions: BlobUtilities.SharedAccessPermissions.READ, - Start: startDate, Expiry: expiryDate } }; @@ -1242,7 +1240,6 @@ describe('BlobService', function () { var sharedAccessPolicy = { AccessPolicy: { Permissions: BlobUtilities.SharedAccessPermissions.READ, - Start: startDate, Expiry: expiryDate } }; diff --git a/test/services/blob/blobservice-uploaddownload-tests.js b/test/services/blob/blobservice-uploaddownload-tests.js index 38005177..9e207fcf 100644 --- a/test/services/blob/blobservice-uploaddownload-tests.js +++ b/test/services/blob/blobservice-uploaddownload-tests.js @@ -24,9 +24,9 @@ var path = require('path'); var testutil = require('../../framework/util'); // Lib includes -var azureutil = testutil.libRequire('/common/lib/util/util'); -var SR = testutil.libRequire('/common/lib/util/sr'); +var azureutil = testutil.libRequire('/common/util/util'); var azure = testutil.libRequire('azure-storage'); +var SR = azure.SR; var Constants = azure.Constants; var HttpConstants = Constants.HttpConstants; var HeaderConstants = Constants.HeaderConstants; @@ -72,7 +72,8 @@ function writeFile(fileName, content) { describe('blob-uploaddownload-tests', function () { before(function (done) { - blobService = azure.createBlobService(); + blobService = azure.createBlobService() + .withFilter(new azure.ExponentialRetryPolicyFilter()); done(); }); diff --git a/test/services/queue/queueservice-tests.js b/test/services/queue/queueservice-tests.js index 8498f8bc..7a8f3476 100644 --- a/test/services/queue/queueservice-tests.js +++ b/test/services/queue/queueservice-tests.js @@ -892,7 +892,6 @@ describe('QueueServiceTests', function() { var sharedAccessPolicy = [{ AccessPolicy: { Permissions: QueueUtilities.SharedAccessPermissions.PROCESS, - Start: startDate, Expiry: expiryDate }, Id: id, diff --git a/test/services/table/tablebatch-tests.js b/test/services/table/tablebatch-tests.js index 947a123f..1ef337a7 100644 --- a/test/services/table/tablebatch-tests.js +++ b/test/services/table/tablebatch-tests.js @@ -23,8 +23,8 @@ var tabletestutil = require('./table-test-utils'); // Lib includes var azure = testutil.libRequire('azure-storage'); -var azureutil = testutil.libRequire('common/lib/util/util'); -var SR = testutil.libRequire('common/lib/util/sr'); +var azureutil = testutil.libRequire('common/util/util'); +var SR = azure.SR; var TableBatch = azure.TableBatch; var TableQuery = azure.TableQuery; var eg = azure.TableUtilities.entityGenerator; diff --git a/test/services/table/tabledatatype-tests.js b/test/services/table/tabledatatype-tests.js index 4245f160..c2ef3d50 100644 --- a/test/services/table/tabledatatype-tests.js +++ b/test/services/table/tabledatatype-tests.js @@ -24,7 +24,7 @@ var tabletestutil = require('./table-test-utils'); // Lib includes var azure = testutil.libRequire('azure-storage'); -var azureutil = testutil.libRequire('common/lib/util/util'); +var azureutil = testutil.libRequire('common/util/util'); var eg = azure.TableUtilities.entityGenerator; var TableUtilities = azure.TableUtilities; diff --git a/test/services/table/tablepayload-tests.js b/test/services/table/tablepayload-tests.js index dd27767a..b73d9ce1 100644 --- a/test/services/table/tablepayload-tests.js +++ b/test/services/table/tablepayload-tests.js @@ -24,7 +24,7 @@ var testutil = require('../../framework/util'); // Lib includes var azure = testutil.libRequire('azure-storage'); -var azureutil = testutil.libRequire('common/lib/util/util'); +var azureutil = testutil.libRequire('common/util/util'); var TableQuery = azure.TableQuery; var TableUtilities = azure.TableUtilities; diff --git a/test/services/table/tablequery-tests.js b/test/services/table/tablequery-tests.js index faa47f03..d5bceb9f 100644 --- a/test/services/table/tablequery-tests.js +++ b/test/services/table/tablequery-tests.js @@ -26,8 +26,7 @@ var azure = testutil.libRequire('azure-storage'); var TableQuery = azure.TableQuery; var TableBatch = azure.TableBatch; -var Constants = testutil.libRequire('common/lib/util/constants'); -var QueryStringConstants = Constants.QueryStringConstants; +var QueryStringConstants = azure.Constants.QueryStringConstants; var TableUtilities = azure.TableUtilities; var eg = TableUtilities.entityGenerator; diff --git a/test/services/table/tableservice-tests.js b/test/services/table/tableservice-tests.js index f2fb4966..d1f3413f 100644 --- a/test/services/table/tableservice-tests.js +++ b/test/services/table/tableservice-tests.js @@ -24,7 +24,7 @@ var tabletestutil = require('./table-test-utils'); // Lib includes var azure = testutil.libRequire('azure-storage'); -var azureutil = testutil.libRequire('common/lib/util/util'); +var azureutil = testutil.libRequire('common/util/util'); var TableQuery = azure.TableQuery; var Constants = azure.Constants;