Code coverage report for lib\common\util\accesscondition.js

Statements: 96.43% (27 / 28)      Branches: 50% (2 / 4)      Functions: 85.71% (6 / 7)      Lines: 96.43% (27 / 28)      Ignored: none     

All files » lib/common/util/ » accesscondition.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123                                                  1   1             1                     1 1 1 1                   1 1 1 1                       1 1 1 1                       1 1 1 1                       1 1 1 1                       1 1 1 1  
// 
// 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.
// 
 
// Expose 'AccessCondition'.
 
/**
* Defines constants, enums, and utility functions for use with storage access condition.
* @namespace
*/
 
'use strict';
 
var constants = require('./constants');
 
exports = module.exports;
 
/**
* Constructs an empty access condition.
*
* @return {object} An empty AccessCondition object
*/
exports.generateEmptyCondition = function () {
  return {};
};
 
/**
* Constructs an access condition such that an operation will be performed only if the resource does not exist on the service
*
* Setting this access condition modifies the request to include the HTTP If-None-Match conditional header
 
* @return {object} An AccessCondition object that represents a condition that checks for nonexistence
*/
exports.generateIfNotExistsCondition = function () {
  var accessCondition = {};
  accessCondition[constants.HeaderConstants.IF_NONE_MATCH] = '*';
  return accessCondition;
};
 
/**
* Constructs an access condition such that an operation will be performed only if the resource exists on the service
*
* Setting this access condition modifies the request to include the HTTP If-Match conditional header
 
* @return {object} An AccessCondition object that represents a condition that checks for existence
*/
exports.generateIfExistsCondition = function () {
  var accessCondition = {};
  accessCondition[constants.HeaderConstants.IF_MATCH] = '*';
  return accessCondition;
};
 
/**
* Constructs an access condition such that an operation will be performed only if the resource's ETag value 
* does not match the specified ETag value
*
* Setting this access condition modifies the request to include the HTTP If-None-Match conditional header
*
* @param  {string} etag                    The ETag value to check against the resource's ETag
* @return {object}                         An AccessCondition object that represents the If-None-Match condition
*/
exports.generateIfNoneMatchCondition = function (etag) {
  var accessCondition = {};
  accessCondition[constants.HeaderConstants.IF_NONE_MATCH] = etag;
  return accessCondition;
};
 
/**
* Constructs an access condition such that an operation will be performed only if the resource's ETag value
* matches the specified ETag value
*
* Setting this access condition modifies the request to include the HTTP If-Match conditional header
*
* @param  {string} etag                    The ETag value to check against the resource's ETag
* @return {object}                         An AccessCondition object that represents the If-Match condition
*/
exports.generateIfMatchCondition = function (etag) {
  var accessCondition = {};
  accessCondition[constants.HeaderConstants.IF_MATCH] = etag;
  return accessCondition;
};
 
/**
* Constructs an access condition such that an operation will be performed only if the resource has been
* modified since the specified time
*
* Setting this access condition modifies the request to include the HTTP If-Modified-Since conditional header
*
* @param  {Date|string}  time              A date object specifying the time since which the resource must have been modified
* @return {object}                         An AccessCondition object that represents the If-Modified-Since condition
*/
exports.generateIfModifiedSinceCondition = function (time) {
  var accessCondition = {};
  accessCondition[constants.HeaderConstants.IF_MODIFIED_SINCE] = time instanceof Date ? time.toUTCString() : time;
  return accessCondition;
};
 
/**
* Constructs an access condition such that an operation will be performed only if the resource has not been
* modified since the specified time
*
* Setting this access condition modifies the request to include the HTTP If-Unmodified-Since conditional header
*
* @param  {Date|string}    time            A date object specifying the time since which the resource must have not been modified
* @return {object}                         An AccessCondition object that represents the If-Unmodified-Since condition
*/
exports.generateIfNotModifiedSinceCondition = function (time) {
  var accessCondition = {};
  accessCondition[constants.HeaderConstants.IF_UNMODIFIED_SINCE] = time instanceof Date ? time.toUTCString() : time;
  return accessCondition;
};