Node.js SDK Release 1.7.0
This commit is contained in:
Rajesh Nagpal 2016-04-26 13:21:42 -07:00
Родитель b21e31e556
Коммит 2a8e87d779
8 изменённых файлов: 375 добавлений и 27 удалений

Просмотреть файл

@ -1 +1 @@
Please read the contributing guidelines from the [Azure Team](http://azure.github.io/guidelines/)
Please read the contributing guidelines from the [Azure Team](https://azure.microsoft.com/en-us/blog/simple-contribution-to-azure-documentation-and-sdk/)

Просмотреть файл

@ -21,6 +21,7 @@
<Content Include="package.json" />
<Content Include="changelog.md" />
<Content Include="readme.html" />
<Content Include="test\mocha.json" />
<Content Include="test\readme.md" />
</ItemGroup>
<ItemGroup>

Просмотреть файл

@ -1,12 +1,16 @@
## Changes in 1.7.0 : ##
- Added the support for TimeToLive(TTL) feature for documents.
## Changes in 1.6.0 : ##
- Added support for Partitioned Collections
- Added support for new offer types
- Added support for Partitioned Collections.
- Added support for new offer types.
## Changes in 1.5.6 : ##
- Fixed RangePartitionResolver.resolveForRead bug where it was not returning links due to a bad concat of results
- Move compareFunction from Range class to RangePartitionResolver class
- Fixed RangePartitionResolver.resolveForRead bug where it was not returning links due to a bad concat of results.
- Move compareFunction from Range class to RangePartitionResolver class.
## Changes in 1.5.5 : ##
@ -18,7 +22,7 @@
## Changes in 1.5.3 : ##
- Properly handle dashes in the mediaIds
- Properly handle dashes in the mediaIds.
## Changes in 1.5.2 : ##
@ -40,17 +44,17 @@
## Changes in 1.3.0 : ##
- Skipped to bring version numbers in alignment with other SDKs
- Skipped to bring version numbers in alignment with other SDKs.
## Changes in 1.2.2 : ##
- Split Q promises wrapper to new repository
- Update to package file for npm registry
- Split Q promises wrapper to new repository.
- Update to package file for npm registry.
## Changes in 1.2.1 : ##
- Implements ID Based Routing
- Fixes Issue [#49](https://github.com/Azure/azure-documentdb-node/issues/49) - current property conflicts with method current()
- Implements ID Based Routing.
- Fixes Issue [#49](https://github.com/Azure/azure-documentdb-node/issues/49) - current property conflicts with method current().
## Changes in 1.2.0 : ##
@ -60,11 +64,11 @@
## Changes in 1.1.0 : ##
- Implements V2 indexing policy
- Implements V2 indexing policy.
## Changes in 1.0.3 : ##
- Issue [#40] (https://github.com/Azure/azure-documentdb-node/issues/40) - Implemented eslint and grunt configurations in the core and promise SDK
- Issue [#40] (https://github.com/Azure/azure-documentdb-node/issues/40) - Implemented eslint and grunt configurations in the core and promise SDK.
## Changes in 1.0.2 : ##
@ -72,6 +76,6 @@
## Changes in 1.0.1 : ##
- Implemented ability to query for conflicts by adding readConflicts, readConflictAsync, queryConflicts;
- Updated API documentation
- Issue [#41](https://github.com/Azure/azure-documentdb-node/issues/41) - client.createDocumentAsync error
- Implemented ability to query for conflicts by adding readConflicts, readConflictAsync, queryConflicts.
- Updated API documentation.
- Issue [#41](https://github.com/Azure/azure-documentdb-node/issues/41) - client.createDocumentAsync error.

Просмотреть файл

@ -151,7 +151,7 @@ var Constants = {
CurrentVersion: "2015-12-16",
UserAgent: "documentdb-nodejs-sdk-1.6.0",
UserAgent: "documentdb-nodejs-sdk-1.7.0",
DefaultPrecisions: {
DefaultNumberHashPrecision: 3,
@ -174,4 +174,4 @@ var Constants = {
if (typeof exports !== "undefined") {
module.exports = Constants;
}
}

Просмотреть файл

@ -123,6 +123,7 @@ var DocumentClient = Base.defineClass(
* @param {object} body - Represents the body of the collection.
* @param {string} body.id - The id of the collection.
* @param {IndexingPolicy} body.indexingPolicy - The indexing policy associated with the collection.
* @param {number} body.defaultTtl - The default time to live in seconds for documents in a collection.
* @param {RequestOptions} [options] - The request options.
* @param {RequestCallback} callback - The callback for the request.
*/
@ -155,6 +156,7 @@ var DocumentClient = Base.defineClass(
* @param {string} documentsFeedOrDatabaseLink - The collection link or database link if using a partition resolver
* @param {object} body - Represents the body of the document. Can contain any number of user defined properties.
* @param {string} [body.id] - The id of the document, MUST be unique for each document.
* @param {number} body.ttl - The time to live in seconds of the document.
* @param {RequestOptions} [options] - The request options.
* @param {boolean} [options.disableAutomaticIdGeneration] - Disables the automatic id generation. If id is missing in the body and this option is true, an error will be returned.
* @param {RequestCallback} callback - The callback for the request.
@ -1488,6 +1490,7 @@ var DocumentClient = Base.defineClass(
* @param {string} documentsFeedOrDatabaseLink - The collection link or database link if using a partition resolver
* @param {object} body - Represents the body of the document. Can contain any number of user defined properties.
* @param {string} [body.id] - The id of the document, MUST be unique for each document.
* @param {number} body.ttl - The time to live in seconds of the document.
* @param {RequestOptions} [options] - The request options.
* @param {boolean} [options.disableAutomaticIdGeneration] - Disables the automatic id generation. If id is missing in the body and this option is true, an error will be returned.
* @param {RequestCallback} callback - The callback for the request.
@ -2445,4 +2448,4 @@ if (typeof exports !== "undefined") {
exports.DocumentBase = AzureDocuments;
exports.Base = Base;
exports.Constants = Constants;
}
}

Просмотреть файл

@ -9,7 +9,7 @@
"database",
"cloud"
],
"version": "1.6.0",
"version": "1.7.0",
"author": "Microsoft Corporation",
"main": "./index.js",
"engine": {
@ -28,10 +28,5 @@
"type": "git",
"url": "https://github.com/Azure/azure-documentdb-node"
},
"licenses": [
{
"type": "Apache License, Version 2.0",
"url": "http://www.apache.org/licenses/LICENSE-2.0"
}
]
"license": "Apache-2.0"
}

3
source/test/mocha.json Normal file
Просмотреть файл

@ -0,0 +1,3 @@
{
"timeout": 10000
}

Просмотреть файл

@ -2932,6 +2932,348 @@ describe("NodeJS CRUD Tests", function () {
});
});
describe("TTL tests", function () {
this.timeout(60000);
var dummyDocumentDefinition = { id: "dummy doc" }
function createCollectionWithInvalidDefaultTtl(client, db, collectionDefinition, collId, defaultTtl, callback) {
collectionDefinition.id = collId;
collectionDefinition.defaultTtl = defaultTtl;
client.createCollection(db._self, collectionDefinition, function (err) {
var badRequestErrorCode = 400;
assert.equal(err.code, badRequestErrorCode, "response should return error code " + badRequestErrorCode);
callback();
});
}
function createDocumentWithInvalidTtl(client, collection, documentDefinition, docId, ttl, callback) {
documentDefinition.id = docId;
documentDefinition.ttl = ttl;
client.createDocument(collection._self, documentDefinition, function (err) {
var badRequestErrorCode = 400;
assert.equal(err.code, badRequestErrorCode, "response should return error code " + badRequestErrorCode);
callback();
});
}
it("[nativeApi] Validate Collection and Document TTL values.", function(done) {
var client = new DocumentDBClient(host, { masterKey: masterKey });
client.createDatabase({ "id": "sample database" }, function(err, db) {
assert.equal(err, undefined, "error creating database");
var collectionDefinition = {
id: "sample collection1",
defaultTtl: 5
};
client.createCollection(db._self, collectionDefinition, function(err, collection) {
assert.equal(err, undefined, "error creating collection");
assert.equal(collectionDefinition.defaultTtl, collection.defaultTtl);
createCollectionWithInvalidDefaultTtl(client, db, collectionDefinition, "sample collection2", null, function() {
createCollectionWithInvalidDefaultTtl(client, db, collectionDefinition, "sample collection3", 0, function() {
createCollectionWithInvalidDefaultTtl(client, db, collectionDefinition, "sample collection4", -10, function() {
var documentDefinition = {
id: "doc",
name: "sample document",
key: "value",
ttl: 2
};
createDocumentWithInvalidTtl(client, collection, documentDefinition, "doc1", 0, function() {
createDocumentWithInvalidTtl(client, collection, documentDefinition, "doc2", null, function() {
createDocumentWithInvalidTtl(client, collection, documentDefinition, "doc3", -10, function() {
done();
});
});
});
});
});
});
});
});
});
function checkDocumentGone(client, collection, createdDocument, callback) {
client.upsertDocument(collection._self, dummyDocumentDefinition, function (err) {
assert.equal(err, undefined, "error upserting document");
client.readDocument(createdDocument._self, function (err) {
var badRequestErrorCode = 404;
assert.equal(err.code, badRequestErrorCode, "response should return error code " + badRequestErrorCode);
callback();
});
});
}
function checkDocumentExists(client, collection, createdDocument, callback) {
client.upsertDocument(collection._self, dummyDocumentDefinition, function (err) {
assert.equal(err, undefined, "error upserting document");
client.readDocument(createdDocument._self, function (err, readDocument) {
assert.equal(err, undefined, "error reading document");
assert.equal(readDocument.ttl, createdDocument.ttl);
callback();
});
});
}
function positiveDefaultTtlStep4(client, collection, createdDocument, callback) {
checkDocumentExists(client, collection, createdDocument, function () {
setTimeout(function() {
checkDocumentGone(client, collection, createdDocument, function() {
callback();
});
}, 3000);
});
}
function positiveDefaultTtlStep3(client, collection, createdDocument, documentDefinition, callback) {
checkDocumentGone(client, collection, createdDocument, function () {
documentDefinition.id = "doc4";
documentDefinition.ttl = 8;
client.createDocument(collection._self, documentDefinition, function (err, createdDocument) {
assert.equal(err, undefined, "error creating document");
setTimeout(positiveDefaultTtlStep4, 6000, client, collection, createdDocument, callback);
});
});
}
function positiveDefaultTtlStep2(client, collection, createdDocument, documentDefinition, callback) {
checkDocumentExists(client, collection, createdDocument, function () {
documentDefinition.id = "doc3";
documentDefinition.ttl = 2;
client.createDocument(collection._self, documentDefinition, function (err, createdDocument) {
assert.equal(err, undefined, "error creating document");
setTimeout(positiveDefaultTtlStep3, 3000, client, collection, createdDocument, documentDefinition, callback);
});
});
}
function positiveDefaultTtlStep1(client, collection, createdDocument, documentDefinition, callback) {
checkDocumentGone(client, collection, createdDocument, function () {
documentDefinition.id = "doc2";
documentDefinition.ttl = -1;
client.createDocument(collection._self, documentDefinition, function (err, createdDocument) {
assert.equal(err, undefined, "error creating document");
setTimeout(positiveDefaultTtlStep2, 6000, client, collection, createdDocument, documentDefinition, callback);
});
});
}
it("[nativeApi] Validate Document TTL with positive defaultTtl.", function (done) {
var client = new DocumentDBClient(host, { masterKey: masterKey });
client.createDatabase({ "id": "sample database" }, function (err, db) {
assert.equal(err, undefined, "error creating database");
var collectionDefinition = {
id: "sample collection",
defaultTtl: 5
};
client.createCollection(db._self, collectionDefinition, function(err, collection) {
assert.equal(err, undefined, "error creating collection");
var documentDefinition = {
id: "doc1",
name: "sample document",
key: "value"
};
client.createDocument(collection._self, documentDefinition, function(err, createdDocument) {
assert.equal(err, undefined, "error creating document");
setTimeout(positiveDefaultTtlStep1, 6000, client, collection, createdDocument, documentDefinition, function() {
done();
});
});
});
});
});
function minusOneDefaultTtlStep1(client, collection, createdDocument1, createdDocument2, createdDocument3, callback) {
checkDocumentGone(client, collection, createdDocument3, function () {
client.readDocument(createdDocument1._self, function (err, readDocument) {
assert.equal(err, undefined, "error reading document");
assert.equal(readDocument.id, createdDocument1.id);
client.readDocument(createdDocument2._self, function (err, readDocument) {
assert.equal(err, undefined, "error reading document");
assert.equal(readDocument.id, createdDocument2.id);
callback();
});
});
});
}
it("[nativeApi] Validate Document TTL with -1 defaultTtl.", function (done) {
var client = new DocumentDBClient(host, { masterKey: masterKey });
client.createDatabase({ "id": "sample database" }, function (err, db) {
assert.equal(err, undefined, "error creating database");
var collectionDefinition = {
id: "sample collection",
defaultTtl: -1
};
client.createCollection(db._self, collectionDefinition, function (err, collection) {
assert.equal(err, undefined, "error creating collection");
var documentDefinition = {
id: "doc1",
name: "sample document",
key: "value"
};
client.createDocument(collection._self, documentDefinition, function (err, createdDocument1) {
assert.equal(err, undefined, "error creating document");
documentDefinition.id = "doc2";
documentDefinition.ttl = -1;
client.createDocument(collection._self, documentDefinition, function(err, createdDocument2) {
assert.equal(err, undefined, "error creating document");
documentDefinition.id = "doc3";
documentDefinition.ttl = 2;
client.createDocument(collection._self, documentDefinition, function(err, createdDocument3) {
assert.equal(err, undefined, "error creating document");
setTimeout(minusOneDefaultTtlStep1, 3000, client, collection, createdDocument1, createdDocument2, createdDocument3, function() {
done();
});
});
});
});
});
});
});
it("[nativeApi] Validate Document TTL with no defaultTtl.", function (done) {
var client = new DocumentDBClient(host, { masterKey: masterKey });
client.createDatabase({ "id": "sample database" }, function (err, db) {
assert.equal(err, undefined, "error creating database");
var collectionDefinition = { id: "sample collection" }
client.createCollection(db._self, collectionDefinition, function (err, collection) {
assert.equal(err, undefined, "error creating collection");
var documentDefinition = {
id: "doc1",
name: "sample document",
key: "value",
ttl: 5
};
client.createDocument(collection._self, documentDefinition, function (err, createdDocument) {
assert.equal(err, undefined, "error creating document");
setTimeout(checkDocumentExists, 3000, client, collection, createdDocument, function() {
done();
});
});
});
});
});
function miscCasesStep4(client, collection, createdDocument, documentDefinition, callback) {
checkDocumentExists(client, collection, createdDocument, function () {
callback();
});
}
function miscCasesStep3(client, collection, upsertedDocument, documentDefinition, callback) {
checkDocumentGone(client, collection, upsertedDocument, function () {
client.deleteDocument(upsertedDocument._self, function() {
var collectionDefinition = { id: collection.id };
client.replaceCollection(collection._self, collectionDefinition, function(err, replacedCollection) {
assert.equal(err, undefined, "error replacing collection");
documentDefinition.id = "doc2";
client.createDocument(replacedCollection._self, documentDefinition, function(err, createdDocument) {
assert.equal(err, undefined, "error creating document");
setTimeout(miscCasesStep4, 6000, client, replacedCollection, createdDocument, documentDefinition, callback);
});
});
});
});
}
function miscCasesStep2(client, collection, documentDefinition, callback) {
client.upsertDocument(collection._self, dummyDocumentDefinition, function(err) {
assert.equal(err, undefined, "error upserting document");
documentDefinition.key = "value2";
client.upsertDocument(collection._self, documentDefinition, function(err, upsertedDocument) {
setTimeout(function() {
checkDocumentExists(client, collection, upsertedDocument, function() {
setTimeout(miscCasesStep3, 3000, client, collection, upsertedDocument, documentDefinition, callback);
});
}, 6000);
});
});
}
function miscCasesStep1(client, collection, createdDocument, documentDefinition, callback) {
checkDocumentGone(client, collection, createdDocument, function () {
client.createDocument(collection._self, documentDefinition, function (err, createdDocument) {
assert.equal(err, undefined, "error creating document");
assert.equal(documentDefinition.id, createdDocument.id);
setTimeout(miscCasesStep2, 3000, client, collection, documentDefinition, callback);
});
});
}
it("[nativeApi] Validate Document TTL Misc cases.", function(done) {
var client = new DocumentDBClient(host, { masterKey: masterKey });
client.createDatabase({ "id": "sample database" }, function(err, db) {
assert.equal(err, undefined, "error creating database");
var collectionDefinition = {
id: "sample collection",
defaultTtl: 8
};
client.createCollection(db._self, collectionDefinition, function(err, collection) {
assert.equal(err, undefined, "error creating collection");
var documentDefinition = {
id: "doc1",
name: "sample document",
key: "value"
};
client.createDocument(collection._self, documentDefinition, function(err, createdDocument) {
assert.equal(err, undefined, "error creating document");
setTimeout(miscCasesStep1, 9000, client, collection, createdDocument, documentDefinition, function() {
done();
});
});
});
});
});
});
describe("HashPartitionResolver", function () {
var test = function (useUpsert, done) {
@ -2979,4 +3321,4 @@ describe("NodeJS CRUD Tests", function () {
it("CRUD operations", function (done) { test(false, done) });
it("CRUD operations with upsert", function (done) { test(true, done) });
});
});
});