Update to version 1.0.0 that has support for offers, removal of obolete properties
This commit is contained in:
Родитель
886b89e211
Коммит
25e28f15e4
|
@ -40,7 +40,7 @@ var AuthHandler = {
|
|||
return resourceTokens[resourceId];
|
||||
} else {
|
||||
var pathParts = path.split("/");
|
||||
var resourceTypes = ["dbs", "colls", "docs", "sprocs", "udfs", "triggers", "users", "permissions", "attachments", "media", "conflicts"];
|
||||
var resourceTypes = ["dbs", "colls", "docs", "sprocs", "udfs", "triggers", "users", "permissions", "attachments", "media", "conflicts", "offers"];
|
||||
for (var i = pathParts.length - 1; i >= 0;i--) {
|
||||
if (resourceTypes.indexOf(pathParts[i]) === -1) {
|
||||
if (resourceTokens[pathParts[i]]) {
|
||||
|
|
|
@ -186,7 +186,10 @@ var Base = {
|
|||
if (options.postTriggerInclude) {
|
||||
headers[Constants.HttpHeaders.PostTriggerInclude] = options.postTriggerInclude.constructor === Array? options.postTriggerInclude.join(","): options.postTriggerInclude;
|
||||
}
|
||||
|
||||
|
||||
if (options.offerType != null) {
|
||||
headers[Constants.HttpHeaders.OfferType] = options.offerType;
|
||||
}
|
||||
|
||||
if (options.maxItemCount) {
|
||||
headers[Constants.HttpHeaders.PageSize] = options.maxItemCount;
|
||||
|
|
|
@ -111,21 +111,19 @@ var Constants = {
|
|||
CollectionCurrentUsageInMb: "x-ms-collection-usage-mb",
|
||||
MaxMediaStorageUsageInMB: "x-ms-max-media-storage-usage-mb",
|
||||
CurrentMediaStorageUsageInMB: "x-ms-media-storage-usage-mb",
|
||||
DatabaseAccountCapacityUnitsConsumed: "x-ms-database-capacity-units-consumed",
|
||||
DatabaseAccountCapacityUnitsProvisioned: "x-ms-database-capacity-units-provisioned",
|
||||
DatabaseAccountConsumedDocumentStorageInMB: "x-ms-databaseaccount-consumed-mb",
|
||||
DatabaseAccountReservedDocumentStorageInMB: "x-ms-databaseaccount-reserved-mb",
|
||||
DatabaseAccountProvisionedDocumentStorageInMB: "x-ms-databaseaccount-provisioned-mb",
|
||||
RequestCharge: "x-ms-request-charge"
|
||||
RequestCharge: "x-ms-request-charge",
|
||||
|
||||
// Offer header
|
||||
OfferType: "x-ms-offer-type"
|
||||
},
|
||||
|
||||
CurrentVersion: "2014-08-21",
|
||||
CurrentVersion: "2015-04-08",
|
||||
|
||||
UserAgent: "documentdb-nodejs-sdk-0.9.3"
|
||||
UserAgent: "documentdb-nodejs-sdk-1.0.0"
|
||||
}
|
||||
|
||||
//SCRIPT END
|
||||
|
||||
if (typeof exports !== "undefined") {
|
||||
module.exports = Constants;
|
||||
}
|
||||
}
|
|
@ -537,7 +537,7 @@ var DocumentClient = Base.defineClass(
|
|||
this.read(path, "conflicts", resourceInfo.objectBody.id, undefined, options, callback);
|
||||
},
|
||||
|
||||
/** lLsts all databases.
|
||||
/** Lists all databases.
|
||||
* @memberof DocumentClient
|
||||
* @instance
|
||||
* @param {FeedOptions} [options] - The feed options.
|
||||
|
@ -1100,26 +1100,6 @@ var DocumentClient = Base.defineClass(
|
|||
this.deleteResource(path, "conflicts", resourceInfo.objectBody.id, undefined, options, callback);
|
||||
},
|
||||
|
||||
/**
|
||||
* Replace the database object.
|
||||
* @memberof DocumentClient
|
||||
* @instance
|
||||
* @param {string} databaseLink - The self-link of the database.
|
||||
* @param {object} db - Represent the new database body.
|
||||
* @param {RequestOptions} [options] - The request options.
|
||||
* @param {RequestCallback} callback - The callback for the request.
|
||||
*/
|
||||
replaceDatabase: function (databaseLink, db, options, callback) {
|
||||
if (!callback) {
|
||||
callback = options;
|
||||
options = {};
|
||||
}
|
||||
|
||||
var path = "/" + databaseLink;
|
||||
var resourceInfo = Base.parsePath(databaseLink);
|
||||
this.replace(db, path, "dbs", resourceInfo.objectBody.id, undefined, options, callback);
|
||||
},
|
||||
|
||||
/**
|
||||
* Replace the document object.
|
||||
* @memberof DocumentClient
|
||||
|
@ -1366,7 +1346,66 @@ var DocumentClient = Base.defineClass(
|
|||
|
||||
this.post(urlConnection, path, params, headers, callback);
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Replace the offer object.
|
||||
* @memberof DocumentClient
|
||||
* @instance
|
||||
* @param {string} offerLink - The self-link of the offer.
|
||||
* @param {object} offer - Represent the new offer body.
|
||||
* @param {RequestCallback} callback - The callback for the request.
|
||||
*/
|
||||
replaceOffer: function (offerLink, offer, callback) {
|
||||
var path = "/" + offerLink;
|
||||
var resourceInfo = Base.parsePath(offerLink);
|
||||
this.replace(offer, path, "offers", resourceInfo.objectBody.id, undefined, {}, callback);
|
||||
},
|
||||
|
||||
/** Reads an offer.
|
||||
* @memberof DocumentClient
|
||||
* @instance
|
||||
* @param {string} offerLink - The self-link of the offer.
|
||||
* @param {RequestCallback} callback - The callback for the request.
|
||||
*/
|
||||
readOffer: function (offerLink, callback) {
|
||||
var path = "/" + offerLink;
|
||||
var resourceInfo = Base.parsePath(offerLink);
|
||||
this.read(path, "offers", resourceInfo.objectBody.id, undefined, {}, callback);
|
||||
},
|
||||
|
||||
/** Lists all offers.
|
||||
* @memberof DocumentClient
|
||||
* @instance
|
||||
* @param {FeedOptions} [options] - The feed options.
|
||||
* @returns {QueryIterator} - An instance of queryIterator to handle reading feed.
|
||||
*/
|
||||
readOffers: function (options) {
|
||||
return this.queryOffers(undefined, options);
|
||||
},
|
||||
|
||||
/** Lists all offers that satisfy a query.
|
||||
* @memberof DocumentClient
|
||||
* @instance
|
||||
* @param {SqlQuerySpec | string} query - A SQL query.
|
||||
* @param {FeedOptions} [options] - The feed options.
|
||||
* @returns {QueryIterator} - An instance of QueryIterator to handle reading feed.
|
||||
*/
|
||||
queryOffers: function (query, options) {
|
||||
var that = this;
|
||||
return new QueryIterator(this, query, options, function (options, callback) {
|
||||
that.queryFeed.call(that,
|
||||
that,
|
||||
"/offers",
|
||||
"offers",
|
||||
"",
|
||||
function (result) { return result.Offers; },
|
||||
function (parent, body) { return body; },
|
||||
query,
|
||||
options,
|
||||
callback);
|
||||
});
|
||||
},
|
||||
|
||||
/** Gets the Database account information.
|
||||
* @memberof DocumentClient
|
||||
* @instance
|
||||
|
@ -1382,11 +1421,6 @@ var DocumentClient = Base.defineClass(
|
|||
databaseAccount.MediaLink = "/media/";
|
||||
databaseAccount.MaxMediaStorageUsageInMB = headers[Constants.HttpHeaders.MaxMediaStorageUsageInMB];
|
||||
databaseAccount.CurrentMediaStorageUsageInMB = headers[Constants.HttpHeaders.CurrentMediaStorageUsageInMB];
|
||||
databaseAccount.CapacityUnitsConsumed = headers[Constants.HttpHeaders.DatabaseAccountCapacityUnitsConsumed];
|
||||
databaseAccount.CapacityUnitsProvisioned = headers[Constants.HttpHeaders.DatabaseAccountCapacityUnitsProvisioned];
|
||||
databaseAccount.ConsumedDocumentStorageInMB = headers[Constants.HttpHeaders.DatabaseAccountConsumedDocumentStorageInMB];
|
||||
databaseAccount.ReservedDocumentStorageInMB = headers[Constants.HttpHeaders.DatabaseAccountReservedDocumentStorageInMB];
|
||||
databaseAccount.ProvisionedDocumentStorageInMB = headers[Constants.HttpHeaders.DatabaseAccountProvisionedDocumentStorageInMB];
|
||||
databaseAccount.ConsistencyPolicy = result.userConsistencyPolicy;
|
||||
|
||||
callback(undefined, databaseAccount, headers);
|
||||
|
@ -1519,6 +1553,7 @@ var DocumentClient = Base.defineClass(
|
|||
* @property {string} [consistencyLevel] - Consistency level required by the client.
|
||||
* @property {string} [sessionToken] - Token for use with Session consistency.
|
||||
* @property {number} [resourceTokenExpirySeconds]- Expiry time (in seconds) for resource token associated with permission (applicable only for requests on permissions).
|
||||
* @property {string} [offerType] - Offer type when creating document collections.
|
||||
*/
|
||||
|
||||
/**
|
||||
|
|
|
@ -17,16 +17,6 @@ var AzureDocuments = Base.defineClass(null, null,
|
|||
* @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>
|
||||
* @property {number} CapacityUnitsConsumed - The number is capacity units database account is currently consuming. <br>
|
||||
Value is returned from cached information updated periodically and is not guaranteed to be real time. </p>
|
||||
* @property {number} CapacityUnitsProvisioned - <p> The number of provisioned capacity units for the database account. <br>
|
||||
Value is returned from cached information updated periodically and is not guaranteed to be real time. </p>
|
||||
* @property {number} ConsumedDocumentStorageInMB - <p> The cumulative sum of current sizes of created collection in MB. <br>
|
||||
Value is returned from cached information updated periodically and is not guaranteed to be real time. </p>
|
||||
* @property {number} ReservedDocumentStorageInMB - <p> The cumulative sum of maximum sizes of created collection in MB. <br>
|
||||
Value is returned from cached information updated periodically and is not guaranteed to be real time. </p>
|
||||
* @property {number} ProvisionedDocumentStorageInMB - <p> The provisioned documented storage capacity for the database account. <br>
|
||||
Value is returned from cached information updated periodically and is not guaranteed to be real time. </p>
|
||||
* @property {object} ConsistencyPolicy - Gets the UserConsistencyPolicy settings.
|
||||
* @property {string} ConsistencyPolicy.defaultConsistencyLevel - The default consistency level and it's of type {@link ConsistencyLevel}.
|
||||
* @property {number} ConsistencyPolicy.maxStalenessPrefix - In bounded staleness consistency, the maximum allowed staleness in terms difference in sequence numbers (aka version).
|
||||
|
@ -61,20 +51,6 @@ var AzureDocuments = Base.defineClass(null, null,
|
|||
enumerable: true
|
||||
});
|
||||
|
||||
Object.defineProperty(this, "CapacityUnitsConsumed", {
|
||||
value: 0,
|
||||
writable: true,
|
||||
configurable: true,
|
||||
enumerable: true
|
||||
});
|
||||
|
||||
Object.defineProperty(this, "CapacityUnitsProvisioned", {
|
||||
value: 0,
|
||||
writable: true,
|
||||
configurable: true,
|
||||
enumerable: true
|
||||
});
|
||||
|
||||
Object.defineProperty(this, "ConsumedDocumentStorageInMB", {
|
||||
value: 0,
|
||||
writable: true,
|
||||
|
@ -155,14 +131,8 @@ var AzureDocuments = Base.defineClass(null, null,
|
|||
Range: "Range",
|
||||
}),
|
||||
|
||||
Protocol : Object.freeze({
|
||||
Tcp: 1,
|
||||
Https: 2,
|
||||
}),
|
||||
|
||||
ConnectionMode : Object.freeze({
|
||||
Direct: 0,
|
||||
Gateway: 1,
|
||||
Gateway: 0,
|
||||
}),
|
||||
|
||||
QueryCompatibilityMode: Object.freeze({
|
||||
|
@ -250,20 +220,6 @@ var AzureDocuments = Base.defineClass(null, null,
|
|||
* @property {number} RequestTimeout - Request timeout (time to wait for response from network peer). Represented in milliseconds.
|
||||
*/
|
||||
ConnectionPolicy : Base.defineClass(function() {
|
||||
Object.defineProperty(this, "_defaultMaxConnections", {
|
||||
value: 20,
|
||||
writable: true,
|
||||
configurable: true,
|
||||
enumerable: false // this is the default value, so it could be excluded during JSON.stringify
|
||||
});
|
||||
|
||||
Object.defineProperty(this, "_defaultMaxConcurrentCallsPerConnection", {
|
||||
value: 50,
|
||||
writable: true,
|
||||
configurable: true,
|
||||
enumerable: false // this is the default value, so it could be excluded during JSON.stringify
|
||||
});
|
||||
|
||||
Object.defineProperty(this, "_defaultRequestTimeout", {
|
||||
value: 60000,
|
||||
writable: true,
|
||||
|
@ -280,12 +236,9 @@ var AzureDocuments = Base.defineClass(null, null,
|
|||
});
|
||||
|
||||
this.ConnectionMode = AzureDocuments.ConnectionMode.Gateway;
|
||||
this.ConnectionProtocol = AzureDocuments.Protocol.Https;
|
||||
this.MediaReadMode = AzureDocuments.MediaReadMode.Buffered;
|
||||
this.MediaRequestTimeout = this._defaultMediaRequestTimeout;
|
||||
this.RequestTimeout = this._defaultRequestTimeout;
|
||||
this.MaxCallsPerConnections = this._defaultMaxConcurrentCallsPerConnection; // for direct connectivity
|
||||
this.MaxConnections = this._defaultMaxConnections; // for direct connectivity
|
||||
})
|
||||
}
|
||||
);
|
||||
|
|
|
@ -14,7 +14,8 @@ var Documents = require('./documents')
|
|||
https.globalAgent.maxSockets = 10000;
|
||||
// setting security protocol for the global agent.
|
||||
https.globalAgent.options.secureProtocol = "TLSv1_client_method";
|
||||
|
||||
// Keeping the connection alive to reuse the sockets.
|
||||
https.globalAgent.keepAlive = true;
|
||||
//----------------------------------------------------------------------------
|
||||
// Utility methods
|
||||
//
|
||||
|
@ -123,7 +124,7 @@ var RequestHandler = {
|
|||
requestOptions.method = method;
|
||||
requestOptions.path = path;
|
||||
requestOptions.headers = headers;
|
||||
|
||||
|
||||
if(queryParams) {
|
||||
requestOptions.path += "?" + querystring.stringify(queryParams);
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
"database",
|
||||
"cloud"
|
||||
],
|
||||
"version": "0.9.3",
|
||||
"version": "1.0.0",
|
||||
"author": "Microsoft Corporation",
|
||||
"main": "./index.js",
|
||||
"engine": {
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
var DocumentDBClient = require("documentdb").DocumentClient
|
||||
var Base = require("documentdb").Base
|
||||
, DocumentDBClient = require("documentdb").DocumentClient
|
||||
, DocumentBase = require("documentdb").DocumentBase
|
||||
, assert = require("assert")
|
||||
, testConfig = require('./_testConfig')
|
||||
|
@ -76,28 +77,18 @@ describe("NodeJS CRUD Tests", function(){
|
|||
]
|
||||
};
|
||||
client.queryDatabases(querySpec).toArray(function (err, results) {
|
||||
assert(results.length > 0, "number of results for the query should be > 0");
|
||||
//replace database
|
||||
db.id = "replaced db";
|
||||
client.replaceDatabase(db._self, db, function(error, replacedDb){
|
||||
assert.equal(replacedDb.id, "replaced db", "Db name should change");
|
||||
assert.equal(db.id, replacedDb.id, "Db id should stay the same");
|
||||
// read database
|
||||
client.readDatabase(replacedDb._self, function(err, database) {
|
||||
assert.equal(err, undefined, "readDatabase should work successfully");
|
||||
assert.equal(replacedDb.id, database.id);
|
||||
// delete database
|
||||
client.deleteDatabase(replacedDb._self, function(err, res){
|
||||
// read database after deletion
|
||||
client.readDatabase(db._self, function(err, database) {
|
||||
var notFoundErrorCode = 404;
|
||||
assert.equal(err.code, notFoundErrorCode, "response should return error code 404");
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
assert(results.length > 0, "number of results for the query should be > 0");
|
||||
|
||||
// delete database
|
||||
client.deleteDatabase(db._self, function(err, res){
|
||||
// read database after deletion
|
||||
client.readDatabase(db._self, function(err, database) {
|
||||
var notFoundErrorCode = 404;
|
||||
assert.equal(err.code, notFoundErrorCode, "response should return error code 404");
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -1151,7 +1142,153 @@ describe("NodeJS CRUD Tests", function(){
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe("Validate Offer CRUD", function () {
|
||||
var validateOfferResponseBody = function (offer, expectedCollLink, expectedOfferType) {
|
||||
assert(offer.id, "Id cannot be null");
|
||||
assert(offer._rid, "Resource Id (Rid) cannot be null");
|
||||
assert(offer._self, "Self Link cannot be null");
|
||||
assert(offer.resource, "Resource Link cannot be null");
|
||||
assert(offer._self.indexOf(offer.id) != -1, "Offer id not contained in offer self link.");
|
||||
assert.equal(expectedCollLink.replace(/^\/|\/$/g, ''), offer.resource.replace(/^\/|\/$/g, ''));
|
||||
if (expectedOfferType) {
|
||||
assert.equal(expectedOfferType, offer.offerType);
|
||||
}
|
||||
}
|
||||
|
||||
it("[nativeApi] Should do offer read and query operations successfully", function (done) {
|
||||
var client = new DocumentDBClient(host, { masterKey: masterKey });
|
||||
// create database
|
||||
client.createDatabase({ id: "sample database" }, function (err, db) {
|
||||
assert(err === undefined);
|
||||
// create collection
|
||||
client.createCollection(db._self, { id: "sample collection" }, function (err, collection) {
|
||||
assert(err === undefined);
|
||||
client.readOffers({}).toArray(function (err, offers) {
|
||||
assert(err === undefined);
|
||||
assert.equal(offers.length, 1);
|
||||
var expectedOffer = offers[0];
|
||||
validateOfferResponseBody(expectedOffer, collection._self, undefined);
|
||||
// Read the offer
|
||||
client.readOffer(expectedOffer._self, function (err, readOffer) {
|
||||
assert(err === undefined);
|
||||
validateOfferResponseBody(readOffer, collection._self, undefined);
|
||||
// Check if the read offer is what we expected.
|
||||
assert.equal(expectedOffer.id, readOffer.id);
|
||||
assert.equal(expectedOffer._rid, readOffer._rid);
|
||||
assert.equal(expectedOffer._self, readOffer._self);
|
||||
assert.equal(expectedOffer.resource, readOffer.resource);
|
||||
// Read offer with a bad offer link.
|
||||
var badLink = expectedOffer._self.substring(0, expectedOffer._self.length - 1) + 'x/';
|
||||
client.readOffer(badLink, function (err, _) {
|
||||
var notFoundErrorCode = 400;
|
||||
assert.equal(err.code, notFoundErrorCode, "response should return error code 404");
|
||||
|
||||
// Query for offer.
|
||||
var querySpec = {
|
||||
query: 'select * FROM root r WHERE r.id=@id',
|
||||
parameters: [
|
||||
{
|
||||
name: '@id',
|
||||
value: expectedOffer.id
|
||||
}
|
||||
]
|
||||
};
|
||||
client.queryOffers(querySpec).toArray(function (err, offers) {
|
||||
assert(err === undefined);
|
||||
assert.equal(offers.length, 1);
|
||||
var oneOffer = offers[0];
|
||||
validateOfferResponseBody(oneOffer, collection._self, undefined);
|
||||
// Now delete the collection.
|
||||
client.deleteCollection(collection._self, function (err, _) {
|
||||
// read offer after deleting collection.
|
||||
client.readOffer(expectedOffer._self, function (err, _) {
|
||||
var notFoundErrorCode = 404;
|
||||
assert.equal(err.code, notFoundErrorCode, "response should return error code 404");
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it("[nativeApi] Should do offer replace operations successfully", function (done) {
|
||||
var client = new DocumentDBClient(host, { masterKey: masterKey });
|
||||
// create database
|
||||
client.createDatabase({ id: "sample database" }, function (err, db) {
|
||||
assert(err === undefined);
|
||||
// create collection
|
||||
client.createCollection(db._self, { id: "sample collection" }, function (err, collection) {
|
||||
assert(err === undefined);
|
||||
client.readOffers().toArray(function (err, offers) {
|
||||
assert(err === undefined);
|
||||
assert.equal(offers.length, 1);
|
||||
var expectedOffer = offers[0];
|
||||
validateOfferResponseBody(expectedOffer, collection._self, undefined);
|
||||
// Replace the offer.
|
||||
var offerToReplace = Base.extend({}, expectedOffer);
|
||||
offerToReplace.offerType = "S2";
|
||||
client.replaceOffer(offerToReplace._self, offerToReplace, function (err, replacedOffer) {
|
||||
assert(err === undefined);
|
||||
validateOfferResponseBody(replacedOffer, collection._self, "S2");
|
||||
// Check if the replaced offer is what we expect.
|
||||
assert.equal(replacedOffer.id, offerToReplace.id);
|
||||
assert.equal(replacedOffer._rid, offerToReplace._rid);
|
||||
assert.equal(replacedOffer._self, offerToReplace._self);
|
||||
assert.equal(replacedOffer.resource, offerToReplace.resource);
|
||||
// Replace an offer with a bad id.
|
||||
var offerBadId = Base.extend({}, offerToReplace);
|
||||
offerBadId._rid = "NotAllowed";
|
||||
client.replaceOffer(offerBadId._self, offerBadId, function (err, _) {
|
||||
var badRequestErrorCode = 400;
|
||||
assert.equal(err.code, badRequestErrorCode);
|
||||
// Replace an offer with a bad rid.
|
||||
var offerBadRid = Base.extend({}, offerToReplace);
|
||||
offerBadRid._rid = "InvalidRid";
|
||||
client.replaceOffer(offerBadRid._self, offerBadRid, function (err, _) {
|
||||
var badRequestErrorCode = 400;
|
||||
assert.equal(err.code, badRequestErrorCode);
|
||||
// Replace an offer with null id and rid.
|
||||
var offerNullId = Base.extend({}, offerToReplace);
|
||||
offerNullId.id = undefined;
|
||||
offerNullId._rid = undefined;
|
||||
client.replaceOffer(offerNullId._self, offerNullId, function (err, _) {
|
||||
var badRequestErrorCode = 400;
|
||||
assert.equal(err.code, badRequestErrorCode);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it("[nativeApi] Should create collection with specified offer type successfully", function (done) {
|
||||
var client = new DocumentDBClient(host, { masterKey: masterKey });
|
||||
// create database
|
||||
client.createDatabase({ id: "sample database" }, function (err, db) {
|
||||
assert(err === undefined);
|
||||
// create collection
|
||||
client.createCollection(db._self, { id: "sample collection" }, { offerType: "S2" }, function (err, collection) {
|
||||
assert(err === undefined);
|
||||
client.readOffers().toArray(function (err, offers) {
|
||||
assert(err === undefined);
|
||||
assert.equal(offers.length, 1);
|
||||
var expectedOffer = offers[0];
|
||||
assert.equal(expectedOffer.offerType, "S2");
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("validate database account functionality", function () {
|
||||
it("[nativeApi] Should get database account successfully", function (done) {
|
||||
var client = new DocumentDBClient(host, { masterKey: masterKey });
|
||||
|
@ -1160,11 +1297,6 @@ describe("NodeJS CRUD Tests", function(){
|
|||
assert.equal(databaseAccount.MediaLink , "/media/");
|
||||
assert.equal(databaseAccount.MaxMediaStorageUsageInMB, headers["x-ms-max-media-storage-usage-mb"]);
|
||||
assert.equal(databaseAccount.CurrentMediaStorageUsageInMB, headers["x-ms-media-storage-usage-mb"]);
|
||||
assert.equal(databaseAccount.CapacityUnitsConsumed, headers["x-ms-database-capacity-units-consumed"]);
|
||||
assert.equal(databaseAccount.CapacityUnitsProvisioned, headers["x-ms-database-capacity-units-provisioned"]);
|
||||
assert.equal(databaseAccount.ConsumedDocumentStorageInMB, headers["x-ms-databaseaccount-consumed-mb"]);
|
||||
assert.equal(databaseAccount.ReservedDocumentStorageInMB, headers["x-ms-databaseaccount-reserved-mb"]);
|
||||
assert.equal(databaseAccount.ProvisionedDocumentStorageInMB, headers["x-ms-databaseaccount-provisioned-mb"]);
|
||||
assert(databaseAccount.ConsistencyPolicy.defaultConsistencyLevel != undefined);
|
||||
done();
|
||||
});
|
||||
|
|
|
@ -43,27 +43,39 @@ function deleteOperationPromise(contextObject, functionName, resourceLink, optio
|
|||
|
||||
function replaceOperationPromise(contextObject, functionName, resourceLink, newResource, options){
|
||||
var deferred = Q.defer();
|
||||
contextObject[functionName](resourceLink, newResource, options, function (error, resource, responseHeaders) {
|
||||
var callback = function (error, resource, responseHeaders) {
|
||||
if (error) {
|
||||
deferred.reject(error);
|
||||
} else {
|
||||
deferred.resolve({resource: resource, headers: responseHeaders});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (options === undefined) {
|
||||
contextObject[functionName](resourceLink, newResource, callback);
|
||||
} else {
|
||||
contextObject[functionName](resourceLink, newResource, options, callback);
|
||||
}
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function readOperationPromise(contextObject, functionName, resourceLink, options){
|
||||
var deferred = Q.defer();
|
||||
contextObject[functionName](resourceLink, options, function (error, resource, responseHeaders) {
|
||||
var callback = function (error, resource, responseHeaders) {
|
||||
if (error) {
|
||||
deferred.reject(error);
|
||||
} else {
|
||||
deferred.resolve({resource: resource, headers: responseHeaders});
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
if (options === undefined) {
|
||||
contextObject[functionName](resourceLink, callback);
|
||||
} else {
|
||||
contextObject[functionName](resourceLink, options, callback);
|
||||
}
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
|
@ -272,20 +284,6 @@ var DocumentClientWrapper = Base.defineClass(
|
|||
return new QueryIteratorWrapper(this._innerDocumentclient.queryUsers(databaseLink, query, options));
|
||||
},
|
||||
|
||||
/**
|
||||
* Replace the database object.
|
||||
* @memberof DocumentClientWrapper
|
||||
* @instance
|
||||
* @param {string} databaseLink - The self-link of the database.
|
||||
* @param {Database} db - Represent the new database body.
|
||||
* @param {RequestOptions} [options] - The request options.
|
||||
* @Returns {Object} <p>A promise object for the request completion. <br>
|
||||
The onFulfilled callback takes a parameter of type {@link ResourceResponse} and the OnError callback takes a parameter of type {@link ResponseError}</p>
|
||||
*/
|
||||
replaceDatabaseAsync: function (databaseLink, db, options) {
|
||||
return replaceOperationPromise(this._innerDocumentclient, "replaceDatabase", databaseLink, db, options);
|
||||
},
|
||||
|
||||
/**
|
||||
* Delete the database object.
|
||||
* @memberof DocumentClientWrapper
|
||||
|
@ -963,7 +961,55 @@ var DocumentClientWrapper = Base.defineClass(
|
|||
*/
|
||||
deleteConflictAsync: function(conflictLink, options) {
|
||||
return deleteOperationPromise(this._innerDocumentclient, "deleteConflict", conflictLink, options);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Replace the Offer object.
|
||||
* @memberof DocumentClientWrapper
|
||||
* @instance
|
||||
* @param {string} offerLink - The self-link of the offer.
|
||||
* @param {object} offer - Represent the new offer body.
|
||||
* @Returns {Object} <p>A promise object for the request completion. <br>
|
||||
The onFulfilled callback takes a parameter of type {@link ResourceResponse} and the OnError callback takes a parameter of type {@link ResponseError}</p>
|
||||
*/
|
||||
replaceOfferAsync: function(offerLink, offer) {
|
||||
return replaceOperationPromise(this._innerDocumentclient, "replaceOffer", offerLink, offer, undefined);
|
||||
},
|
||||
|
||||
/**
|
||||
* Reads an offer object.
|
||||
* @memberof DocumentClientWrapper
|
||||
* @instance
|
||||
* @param {string} offerLink - The self-link of the offer.
|
||||
* @Returns {Object} <p>A promise object for the request completion. <br>
|
||||
The onFulfilled callback takes a parameter of type {@link ResourceResponse} and the OnError callback takes a parameter of type {@link ResponseError}</p>
|
||||
*/
|
||||
readOfferAsync: function (offerLink) {
|
||||
return readOperationPromise(this._innerDocumentclient, "readOffer", offerLink, undefined);
|
||||
},
|
||||
|
||||
/**
|
||||
* Get all offers for this database.
|
||||
* @memberof DocumentClientWrapper
|
||||
* @instance
|
||||
* @param {FeedOptions} [options] - The feed options
|
||||
* @returns {QueryIterator} - An instance of queryIterator to handle reading feed.
|
||||
*/
|
||||
readOffers: function (options) {
|
||||
return new QueryIteratorWrapper(this._innerDocumentclient.readOffers(options));
|
||||
},
|
||||
|
||||
/**
|
||||
* Query offers for this database.
|
||||
* @memberof DocumentClientWrapper
|
||||
* @instance
|
||||
* @param {SqlQuerySpec | string} query - A SQL query.
|
||||
* @param {FeedOptions} [options] - Represents the feed options.
|
||||
* @returns {QueryIterator} - An instance of queryIterator to handle reading feed.
|
||||
*/
|
||||
queryOffers: function (query, options) {
|
||||
return new QueryIteratorWrapper(this._innerDocumentclient.queryOffers(query, options));
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
"cloud",
|
||||
"promises"
|
||||
],
|
||||
"version": "0.9.3",
|
||||
"version": "1.0.0",
|
||||
"author": "Microsoft Corporation",
|
||||
"main": "./documentclientwrapper.js",
|
||||
"engine": {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
var host = "MyHost";
|
||||
var key = "MyKey";
|
||||
var masterKey = "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==";
|
||||
var host = "https://localhost:443";
|
||||
|
||||
exports.host = host;
|
||||
exports.masterKey = key;
|
||||
exports.masterKey = masterKey;
|
||||
|
|
Загрузка…
Ссылка в новой задаче