diff --git a/types/documentdb/documentdb-tests.ts b/types/documentdb/documentdb-tests.ts index f4a06d3fb7..3395716305 100644 --- a/types/documentdb/documentdb-tests.ts +++ b/types/documentdb/documentdb-tests.ts @@ -1,150 +1,242 @@ +import ddb = require('documentdb'); -import docDB = require('documentdb'); -var docDBClient = new docDB.DocumentClient('host', { masterKey: 'masterKey' }); +/** DocumentClient constructor */ +const permission1: ddb.Permission = { id: '1', permissionMode: 'Read', resource: 'foo' }; +const auth1: ddb.AuthOptions = { masterKey: 'masterKey' }; +const auth2: ddb.AuthOptions = { resourceTokens: {foo: 'bar' }}; +const auth3: ddb.AuthOptions = { permissionFeed: [ permission1 ]}; +const retry1: ddb.RetryOptions = { MaxRetryAttemptCount: 3 }; +const retry2: ddb.RetryOptions = { FixedRetryIntervalInMilliseconds: 1000 }; +const retry3: ddb.RetryOptions = { MaxWaitTimeInSeconds: 20 }; +const connectionPolicy: ddb.ConnectionPolicy = { + MediaReadMode: 'Buffered', MediaRequestTimeout: 1000, RequestTimeout: 1000, + EnableEndpointDiscovery: true, PreferredLocations: ['foo'], + RetryOptions: retry1, DisableSSLVerification: false }; +const client1 = new ddb.DocumentClient('host', auth1); +const client2 = new ddb.DocumentClient('host', auth1, connectionPolicy); +const client3 = new ddb.DocumentClient('host', auth1, connectionPolicy, 'Strong'); -docDBClient.createDatabase({ id: 'foo' }, undefined, (error, result) => { +/** DocumentClient methods */ +const requestOptions1: ddb.RequestOptions = { }; +const mediaOptions1: ddb.MediaOptions = { }; +const docOptions1: ddb.DocumentOptions = { }; +const attachment1: ddb.Attachment = { id: '1', contentType: 'foo/bar', media: 'foo' }; +const stream1: NodeJS.ReadableStream = null; +const index1: ddb.Index = { Kind: 'Hash', DataType: 'foo', Precision: 0.1 }; +const includePath1: ddb.IncludedPath = { Path: 'foo', Indexes: [index1] }; +const excludePath1: ddb.ExcludedPath = { Path: 'foo' }; +const indexingPolicy1: ddb.IndexingPolicy = { automatic: true, indexingMode: 'Consistent', IncludedPaths: [includePath1], ExcludedPaths: [excludePath1]}; +const collection1: ddb.Collection = { id: '1' }; +const collection2: ddb.Collection = { id: '2', indexingPolicy: indexingPolicy1 }; +const collection3: ddb.Collection = { id: '3', defaultTtl: 60 }; +const database1: ddb.UniqueId = { id: '1' }; +const document1: ddb.NewDocument = { id: '1' }; +const document2: ddb.NewDocument = { id: '1', ttl: 60 }; +const sproc1: ddb.Procedure = { id: '1', body() {} }; +const sproc2: ddb.Procedure = { id: '1', body: 'function() {}' }; +const trigger1: ddb.Trigger = { id: '1', triggerOperation: 'All', serverScript() {} }; +const trigger2: ddb.Trigger = { id: '1', triggerOperation: 'All', serverScript: 'function() {}' }; +const trigger3: ddb.Trigger = { id: '1', triggerOperation: 'All', triggerType: 'Pre', serverScript: 'function() {}' }; +const user1: ddb.UniqueId = { id: '1' }; +const udf1: ddb.UserDefinedFunction = { id: '1', serverScript() {} }; +const udf2: ddb.UserDefinedFunction = { id: '1', serverScript: 'function() {}' }; +const udf3: ddb.UserDefinedFunction = { id: '1', serverScript: 'function() {}', userDefinedFunctionType: 'Javascript' }; +const databaseAccountOptions: ddb.DatabaseAccountRequestOptions = { }; +const query1: ddb.DocumentQuery = 'foo'; +const query2: ddb.DocumentQuery = { query: 'foo', parameters: [ {name: 'foo', value: 'bar' }] }; +const feedOptions1: ddb.FeedOptions = { }; - if (error) { - throw new Error(error.body); - } - else { - console.log('Created database: ' + result.id); - } -}); +client1.createAttachment('foo', attachment1, requestOptions1, (err: ddb.QueryError, resource: ddb.AttachmentMeta, responseHeaders: any) => void 0); +client1.createAttachment('foo', attachment1, (err: ddb.QueryError, resource: ddb.AttachmentMeta, responseHeaders: any) => void 0); +client1.createAttachmentAndUploadMedia('foo', stream1, mediaOptions1, (err: ddb.QueryError, resource: ddb.AttachmentMeta, responseHeaders: any) => void 0); +client1.createAttachmentAndUploadMedia('foo', stream1, (err: ddb.QueryError, resource: ddb.AttachmentMeta, responseHeaders: any) => void 0); +client1.createCollection('foo', collection1, requestOptions1, (err: ddb.QueryError, resource: ddb.CollectionMeta, responseHeaders: any) => void 0); +client1.createCollection('foo', collection1, (err: ddb.QueryError, resource: ddb.CollectionMeta, responseHeaders: any) => void 0); +client1.createDatabase(database1, requestOptions1, (err: ddb.QueryError, resource: ddb.DatabaseMeta, responseHeaders: any) => void 0); +client1.createDatabase(database1, (err: ddb.QueryError, resource: ddb.DatabaseMeta, responseHeaders: any) => void 0); +client1.createDocument('foo', document1, docOptions1, (err: ddb.QueryError, resource: ddb.RetrievedDocument, responseHeaders: any) => void 0); +client1.createDocument('foo', document1, (err: ddb.QueryError, resource: ddb.RetrievedDocument, responseHeaders: any) => void 0); +client1.createPermission('foo', permission1, requestOptions1, (err: ddb.QueryError, resource: ddb.PermissionMeta, responseHeaders: any) => void 0); +client1.createPermission('foo', permission1, (err: ddb.QueryError, resource: ddb.PermissionMeta, responseHeaders: any) => void 0); +client1.createStoredProcedure('foo', sproc1, requestOptions1, (err: ddb.QueryError, resource: ddb.ProcedureMeta, responseHeaders: any) => void 0); +client1.createStoredProcedure('foo', sproc1, (err: ddb.QueryError, resource: ddb.ProcedureMeta, responseHeaders: any) => void 0); +client1.createTrigger('foo', trigger1, requestOptions1, (err: ddb.QueryError, resource: ddb.TriggerMeta, responseHeaders: any) => void 0); +client1.createTrigger('foo', trigger1, (err: ddb.QueryError, resource: ddb.TriggerMeta, responseHeaders: any) => void 0); +client1.createUser('foo', user1, requestOptions1, (err: ddb.QueryError, resource: ddb.AbstractMeta, responseHeaders: any) => void 0); +client1.createUser('foo', user1, (err: ddb.QueryError, resource: ddb.AbstractMeta, responseHeaders: any) => void 0); +client1.createUserDefinedFunction('foo', udf1, requestOptions1, (err: ddb.QueryError, resource: ddb.UserDefinedFunctionMeta, responseHeaders: any) => void 0); +client1.createUserDefinedFunction('foo', udf1, (err: ddb.QueryError, resource: ddb.UserDefinedFunctionMeta, responseHeaders: any) => void 0); -var dbQuerySpec: docDB.SqlQuerySpec = {query: 'SELECT * FROM d WHERE d.meta = @meta', parameters: [{name: '@meta', value: {creator: 'John Smith', type: 'documentdb'}}]}; -docDBClient.queryDatabases(dbQuerySpec).toArray((error, result) => { - - if (error) { - throw new Error(error.body); - } - else { - if (result.length < 1) { - throw new Error('Database foo not found'); - } - else { - console.log('Found database: ' + result[0].id); - } - } -}); +client1.deleteAttachment('foo', requestOptions1, (err: ddb.QueryError) => void 0); +client1.deleteAttachment('foo', (err: ddb.QueryError) => void 0); +client1.deleteCollection('foo', requestOptions1, (err: ddb.QueryError) => void 0); +client1.deleteCollection('foo', (err: ddb.QueryError) => void 0); +client1.deleteConflict('foo', requestOptions1, (err: ddb.QueryError) => void 0); +client1.deleteConflict('foo', (err: ddb.QueryError) => void 0); +client1.deleteDatabase('foo', requestOptions1, (err: ddb.QueryError) => void 0); +client1.deleteDatabase('foo', (err: ddb.QueryError) => void 0); +client1.deleteDocument('foo', requestOptions1, (err: ddb.QueryError) => void 0); +client1.deleteDocument('foo', (err: ddb.QueryError) => void 0); +client1.deletePermission('foo', requestOptions1, (err: ddb.QueryError) => void 0); +client1.deletePermission('foo', (err: ddb.QueryError) => void 0); +client1.deleteStoredProcedure('foo', requestOptions1, (err: ddb.QueryError) => void 0); +client1.deleteStoredProcedure('foo', (err: ddb.QueryError) => void 0); +client1.deleteTrigger('foo', requestOptions1, (err: ddb.QueryError) => void 0); +client1.deleteTrigger('foo', (err: ddb.QueryError) => void 0); +client1.deleteUser('foo', requestOptions1, (err: ddb.QueryError) => void 0); +client1.deleteUser('foo', (err: ddb.QueryError) => void 0); +client1.deleteUserDefinedFunction('foo', requestOptions1, (err: ddb.QueryError) => void 0); +client1.deleteUserDefinedFunction('foo', (err: ddb.QueryError) => void 0); -docDBClient.createCollection('database', { id: 'foo' }, undefined, (error, result) => { +client1.executeStoredProcedure('foo', ['1', 1, {}], requestOptions1, (err: ddb.QueryError, resource: any, responseHeaders: any) => void 0); +client1.executeStoredProcedure('foo', requestOptions1, (err: ddb.QueryError, resource: any, responseHeaders: any) => void 0); +client1.executeStoredProcedure('foo', ['1', 1, {}], (err: ddb.QueryError, resource: any, responseHeaders: any) => void 0); - if (error) { - throw new Error(error.body); - } - else { - console.log('Created collection: ' + result.id); - } -}); +client1.getDatabaseAccount(databaseAccountOptions, (err: ddb.QueryError, resource: ddb.DatabaseAccount, responseHeaders: any) => void 0); +client1.getDatabaseAccount((err: ddb.QueryError, resource: ddb.DatabaseAccount, responseHeaders: any) => void 0); +client1.getReadEndpoint((err: ddb.QueryError, resource: string, responseHeaders: any) => void 0); +client1.getWriteEndpoint((err: ddb.QueryError, resource: string, responseHeaders: any) => void 0); -var procedure: docDB.Procedure = { - id: 'procedure-one', - body: function () { - console.log('foo'); - } -}; +const it1: ddb.QueryIterator = client1.queryAttachments('foo', query1, feedOptions1); +const it2: ddb.QueryIterator = client1.queryAttachments('foo', query1); +const it3: ddb.QueryIterator = client1.queryCollections('foo', query1, feedOptions1); +const it4: ddb.QueryIterator = client1.queryCollections('foo', query1); +const it5: ddb.QueryIterator = client1.queryConflicts('foo', query1, feedOptions1); // TODO add type for Conflict +const it6: ddb.QueryIterator = client1.queryConflicts('foo', query1); +const it7: ddb.QueryIterator = client1.queryDatabases(query1, feedOptions1); +const it8: ddb.QueryIterator = client1.queryDatabases(query1); +const it9: ddb.QueryIterator = client1.queryDocuments('foo', query1, feedOptions1); +const it10: ddb.QueryIterator = client1.queryDocuments('foo', query1); +const it11: ddb.QueryIterator = client1.queryOffers(query1, feedOptions1); // TODO add type for Offer +const it12: ddb.QueryIterator = client1.queryOffers(query1); +const it13: ddb.QueryIterator = client1.queryPermissions('foo', query1, feedOptions1); +const it14: ddb.QueryIterator = client1.queryPermissions('foo', query1); +const it15: ddb.QueryIterator = client1.queryStoredProcedures('foo', query1, feedOptions1); +const it16: ddb.QueryIterator = client1.queryStoredProcedures('foo', query1); +const it17: ddb.QueryIterator = client1.queryTriggers('foo', query1, feedOptions1); +const it18: ddb.QueryIterator = client1.queryTriggers('foo', query1); +const it19: ddb.QueryIterator = client1.queryUserDefinedFunctions('foo', query1, feedOptions1); +const it20: ddb.QueryIterator = client1.queryUserDefinedFunctions('foo', query1); +const it21: ddb.QueryIterator = client1.queryUsers('foo', query1, feedOptions1); // TODO add type for User +const it22: ddb.QueryIterator = client1.queryUsers('foo', query1); -docDBClient.createStoredProcedure('collection', procedure, undefined, (error, result) => { +client1.readAttachment('foo', requestOptions1, (err: ddb.QueryError, resource: ddb.AttachmentMeta, responseHeaders: any) => void 0); +client1.readAttachment('foo', (err: ddb.QueryError, resource: ddb.AttachmentMeta, responseHeaders: any) => void 0); +client1.readCollection('foo', requestOptions1, (err: ddb.QueryError, resource: ddb.CollectionMeta, responseHeaders: any) => void 0); +client1.readCollection('foo', (err: ddb.QueryError, resource: ddb.CollectionMeta, responseHeaders: any) => void 0); +client1.readConflict('foo', requestOptions1, (err: ddb.QueryError, resource: any, responseHeaders: any) => void 0); +client1.readConflict('foo', (err: ddb.QueryError, resource: any, responseHeaders: any) => void 0); +client1.readDatabase('foo', requestOptions1, (err: ddb.QueryError, resource: ddb.DatabaseMeta, responseHeaders: any) => void 0); +client1.readDatabase('foo', (err: ddb.QueryError, resource: ddb.DatabaseMeta, responseHeaders: any) => void 0); +client1.readDocument('foo', requestOptions1, (err: ddb.QueryError, resource: ddb.RetrievedDocument, responseHeaders: any) => void 0); +client1.readDocument('foo', (err: ddb.QueryError, resource: ddb.RetrievedDocument, responseHeaders: any) => void 0); +client1.readPermission('foo', requestOptions1, (err: ddb.QueryError, resource: ddb.PermissionMeta, responseHeaders: any) => void 0); +client1.readPermission('foo', (err: ddb.QueryError, resource: ddb.PermissionMeta, responseHeaders: any) => void 0); +client1.readStoredProcedure('foo', requestOptions1, (err: ddb.QueryError, resource: ddb.ProcedureMeta, responseHeaders: any) => void 0); +client1.readStoredProcedure('foo', (err: ddb.QueryError, resource: ddb.ProcedureMeta, responseHeaders: any) => void 0); +client1.readTrigger('foo', requestOptions1, (err: ddb.QueryError, resource: ddb.TriggerMeta, responseHeaders: any) => void 0); +client1.readTrigger('foo', (err: ddb.QueryError, resource: ddb.TriggerMeta, responseHeaders: any) => void 0); +client1.readUserDefinedFunction('foo', requestOptions1, (err: ddb.QueryError, resource: ddb.UserDefinedFunctionMeta, responseHeaders: any) => void 0); +client1.readUserDefinedFunction('foo', (err: ddb.QueryError, resource: ddb.UserDefinedFunctionMeta, responseHeaders: any) => void 0); +client1.readUser('foo', requestOptions1, (err: ddb.QueryError, resource: any, responseHeaders: any) => void 0); +client1.readUser('foo', (err: ddb.QueryError, resource: any, responseHeaders: any) => void 0); +client1.readOffer('foo', (err: ddb.QueryError, resource: any, responseHeaders: any) => void 0); +client1.readMedia('foo', (err: ddb.QueryError, resource: Buffer|NodeJS.ReadableStream, responseHeaders: any) => void 0); - if (error) { - throw new Error(error.body); - } - else { - console.log('Created procedure: ' + result.id); - } -}); +const it23: ddb.QueryIterator = client1.readAttachments('foo', feedOptions1); +const it24: ddb.QueryIterator = client1.readAttachments('foo'); +const it25: ddb.QueryIterator = client1.readCollections('foo', feedOptions1); +const it26: ddb.QueryIterator = client1.readCollections('foo'); +const it27: ddb.QueryIterator = client1.readConflicts('foo', feedOptions1); // TODO +const it28: ddb.QueryIterator = client1.readConflicts('foo'); // TODO +const it29: ddb.QueryIterator = client1.readDatabases(feedOptions1); +const it30: ddb.QueryIterator = client1.readDatabases(); +const it31: ddb.QueryIterator = client1.readDocuments('foo', feedOptions1); +const it32: ddb.QueryIterator = client1.readDocuments('foo'); +const it33: ddb.QueryIterator = client1.readPermissions('foo', feedOptions1); +const it34: ddb.QueryIterator = client1.readPermissions('foo'); +const it35: ddb.QueryIterator = client1.readStoredProcedures('foo', feedOptions1); +const it36: ddb.QueryIterator = client1.readStoredProcedures('foo'); +const it37: ddb.QueryIterator = client1.readTriggers('foo', feedOptions1); +const it38: ddb.QueryIterator = client1.readTriggers('foo'); +const it39: ddb.QueryIterator = client1.readUserDefinedFunctions('foo', feedOptions1); +const it40: ddb.QueryIterator = client1.readUserDefinedFunctions('foo'); +const it41: ddb.QueryIterator = client1.readUsers('foo', feedOptions1); // TODO +const it42: ddb.QueryIterator = client1.readUsers('foo'); // TODO +const it43: ddb.QueryIterator = client1.readOffers(); // TODO -var userDefinedFunction: docDB.UserDefinedFunction = { - id: 'udf1', - body: function () { - console.log('foo'); - } -}; +client1.replaceAttachment('foo', attachment1, requestOptions1, (err: ddb.QueryError, resource: ddb.AttachmentMeta, responseHeaders: any) => void 0); +client1.replaceAttachment('foo', attachment1, (err: ddb.QueryError, resource: ddb.AttachmentMeta, responseHeaders: any) => void 0); +client1.replaceCollection('foo', collection1, requestOptions1, (err: ddb.QueryError, resource: ddb.CollectionMeta, responseHeaders: any) => void 0); +client1.replaceCollection('foo', collection1, (err: ddb.QueryError, resource: ddb.CollectionMeta, responseHeaders: any) => void 0); +client1.replaceDocument('foo', document1, requestOptions1, (err: ddb.QueryError, resource: ddb.RetrievedDocument, responseHeaders: any) => void 0); +client1.replaceDocument('foo', document1, (err: ddb.QueryError, resource: ddb.RetrievedDocument, responseHeaders: any) => void 0); +client1.replacePermission('foo', permission1, requestOptions1, (err: ddb.QueryError, resource: ddb.PermissionMeta, responseHeaders: any) => void 0); +client1.replacePermission('foo', permission1, (err: ddb.QueryError, resource: ddb.PermissionMeta, responseHeaders: any) => void 0); +client1.replaceStoredProcedure('foo', sproc1, requestOptions1, (err: ddb.QueryError, resource: ddb.ProcedureMeta, responseHeaders: any) => void 0); +client1.replaceStoredProcedure('foo', sproc1, (err: ddb.QueryError, resource: ddb.ProcedureMeta, responseHeaders: any) => void 0); +client1.replaceTrigger('foo', trigger1, requestOptions1, (err: ddb.QueryError, resource: ddb.TriggerMeta, responseHeaders: any) => void 0); +client1.replaceTrigger('foo', trigger1, (err: ddb.QueryError, resource: ddb.TriggerMeta, responseHeaders: any) => void 0); +client1.replaceUser('foo', user1, requestOptions1, (err: ddb.QueryError, resource: ddb.AbstractMeta, responseHeaders: any) => void 0); +client1.replaceUser('foo', user1, (err: ddb.QueryError, resource: ddb.AbstractMeta, responseHeaders: any) => void 0); +client1.replaceUserDefinedFunction('foo', udf1, requestOptions1, (err: ddb.QueryError, resource: ddb.UserDefinedFunctionMeta, responseHeaders: any) => void 0); +client1.replaceUserDefinedFunction('foo', udf1, (err: ddb.QueryError, resource: ddb.UserDefinedFunctionMeta, responseHeaders: any) => void 0); +client1.replaceOffer('foo', {}, (err: ddb.QueryError, resource: any, responseHeaders: any) => void 0); -docDBClient.createUserDefinedFunction('collection', userDefinedFunction, undefined, (error, result) => { - if (error) { - throw new Error(error.body); - } - else { - console.log('Created function: ' + result.id); - } -}); +client1.updateMedia('foo', stream1, mediaOptions1, (err: ddb.QueryError, resource: any, responseHeaders: any) => void 0); +client1.updateMedia('foo', stream1, (err: ddb.QueryError, resource: any, responseHeaders: any) => void 0); -docDBClient.queryUserDefinedFunctions('collection', "SELECT * FROM root", undefined).toArray((error, results) => { - if (error) { - throw new Error(error.body); - } - else { - console.log('Number of functions in collection: ' + results.length); - } -}); +client1.upsertAttachment('foo', attachment1, requestOptions1, (err: ddb.QueryError, resource: ddb.AttachmentMeta, responseHeaders: any) => void 0); +client1.upsertAttachment('foo', attachment1, (err: ddb.QueryError, resource: ddb.AttachmentMeta, responseHeaders: any) => void 0); +client1.upsertAttachmentAndUploadMedia('foo', stream1, mediaOptions1, (err: ddb.QueryError, resource: ddb.AttachmentMeta, responseHeaders: any) => void 0); +client1.upsertAttachmentAndUploadMedia('foo', stream1, (err: ddb.QueryError, resource: ddb.AttachmentMeta, responseHeaders: any) => void 0); +client1.upsertDocument('foo', document1, docOptions1, (err: ddb.QueryError, resource: ddb.RetrievedDocument, responseHeaders: any) => void 0); +client1.upsertDocument('foo', document1, (err: ddb.QueryError, resource: ddb.RetrievedDocument, responseHeaders: any) => void 0); +client1.upsertPermission('foo', permission1, requestOptions1, (err: ddb.QueryError, resource: ddb.PermissionMeta, responseHeaders: any) => void 0); +client1.upsertPermission('foo', permission1, (err: ddb.QueryError, resource: ddb.PermissionMeta, responseHeaders: any) => void 0); +client1.upsertStoredProcedure('foo', sproc1, requestOptions1, (err: ddb.QueryError, resource: ddb.Procedure, responseHeaders: any) => void 0); +client1.upsertStoredProcedure('foo', sproc1, (err: ddb.QueryError, resource: ddb.Procedure, responseHeaders: any) => void 0); +client1.upsertTrigger('foo', trigger1, requestOptions1, (err: ddb.QueryError, resource: ddb.TriggerMeta, responseHeaders: any) => void 0); +client1.upsertTrigger('foo', trigger1, (err: ddb.QueryError, resource: ddb.TriggerMeta, responseHeaders: any) => void 0); +client1.upsertUser('foo', user1, requestOptions1, (err: ddb.QueryError, resource: ddb.TriggerMeta, responseHeaders: any) => void 0); +client1.upsertUser('foo', user1, (err: ddb.QueryError, resource: ddb.TriggerMeta, responseHeaders: any) => void 0); +client1.upsertUserDefinedFunction('foo', udf1, requestOptions1, (err: ddb.QueryError, resource: ddb.UserDefinedFunctionMeta, responseHeaders: any) => void 0); +client1.upsertUserDefinedFunction('foo', udf1, (err: ddb.QueryError, resource: ddb.UserDefinedFunctionMeta, responseHeaders: any) => void 0); -var trigger: docDB.Trigger = { - id: 'trigger-one', - body: function () { - console.log('bar'); - }, - triggerType: 'pre', - triggerOperation: 'all' -}; +/** QueryIterator constructor */ +interface Row {foo: string; } +const qi1 = new ddb.QueryIterator(client1, query1, feedOptions1, (err: ddb.QueryError, resource: Row, responseHeaders: any): void => void 0, 'foo'); +const qi2 = new ddb.QueryIterator(client1, query1, feedOptions1, [(err: ddb.QueryError, resource: Row, responseHeaders: any): void => void 0]); -docDBClient.createTrigger('collection', trigger, undefined, (error, result) => { - - if (error) { - throw new Error(error.body); - } - else { - console.log('Created trigger: ' + result.id); - } -}); +/** QueryIterator methods */ +qi1.current((err: ddb.QueryError, resource: Row, responseHeaders: any) => void 0); +qi1.executeNext((err: ddb.QueryError, resource: Row[], responseHeaders: any) => void 0); +qi1.forEach((err: ddb.QueryError, resource: Row, responseHeaders: any) => void 0); +const hasMoreResults1: boolean = qi1.hasMoreResults(); +qi1.nextItem((err: ddb.QueryError, resoure: Row, responseHeaders: any) => void 0); +qi1.reset(); +qi1.toArray((err: ddb.QueryError, resource: Row[], responseHeaders: any) => void 0); -var triggerQuerySpec: docDB.SqlQuerySpec = {query: 'SELECT * FROM t WHERE t.id = @id', parameters: [{name: '@id', value: 'trigger-foo'}]}; -docDBClient.queryTriggers('collection', triggerQuerySpec).toArray((error, result) => { - - if (error) { - throw new Error(error.body); - } - else { - if (result.length < 1) { - throw new Error('Trigger trigger-foo not found'); - } - else { - console.log('Found trigger: ' + result[0].id); - } - } -}); +/** HashPartitionResolver constructor */ +const hashOptions1: ddb.ConsistentHashRingOptions = { computeHash: (obj: any) => obj.foo }; +const hashOptions2: ddb.ConsistentHashRingOptions = { numberOfVirtualNodesPerCollection: 100 }; +const hpr1 = new ddb.HashPartitionResolver('foo', ['dbs/foo/colls/bar'], hashOptions1); +const hpr2 = new ddb.HashPartitionResolver((obj: any) => obj.foo, ['dbs/foo/colls/bar']); -var document: docDB.NewDocument<{ val: string }> = { - id: '10' -}; +/** HashPartitionResolver methods */ +const hashPartitionKey1: any = hpr1.getPartitionKey(document1); +const hashCollectionLink1: string = hpr1.resolveForCreate(hashPartitionKey1); +const hashCollectionLinks1: string[] = hpr1.resolveForRead(hashPartitionKey1); -docDBClient.createDocument('collection', document, undefined, (error, result) => { +/** RangePartitionResolver constructor */ +const range1 = new ddb.Range({low: 0, high: 1}); - if (error) { - throw new Error(error.body); - } - else { - console.log('Created document: ' + result.id); - - docDBClient.replaceDocument(result._self, document, undefined, (subError, subResult) => { - - if (subError) { - throw new Error(subError.body); - } - else { - console.log('Replaced document: ' + subResult.id); - } - }) - } -}); +/** RangePartitionResolver constructor */ +const partitionKeyMap1: ddb.PartitionKeyMap = { link: 'foo', range: range1 }; +const rpr1 = new ddb.RangePartitionResolver('foo', [ partitionKeyMap1 ], (a: any, b: any) => 0); +const rpr2 = new ddb.RangePartitionResolver((obj: any) => obj.foo, [ partitionKeyMap1 ]); -docDBClient.executeStoredProcedure('procedure', [10, 'foo'], (error, result) => { - - if (error) { - throw new Error(error.body); - } - else { - console.log('Procedure result: ' + result); - } -}); \ No newline at end of file +/** HashPartitionResolver methods */ +const rangePartitionKey1: any = rpr1.getPartitionKey(document1); +const rangeCollectionLink1: string = rpr1.resolveForCreate(hashPartitionKey1); +const rangeCollectionLinks1: string[] = rpr1.resolveForRead(hashPartitionKey1); diff --git a/types/documentdb/index.d.ts b/types/documentdb/index.d.ts index 048825b492..a786cae614 100644 --- a/types/documentdb/index.d.ts +++ b/types/documentdb/index.d.ts @@ -1,13 +1,12 @@ -// Type definitions for DocumentDB +// Type definitions for DocumentDB 1.10.2 // Project: https://github.com/Azure/azure-documentdb-node -// Definitions by: Noel Abrahams , Brett Gutstein +// Definitions by: Noel Abrahams , Brett Gutstein , Chris Stone // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped/documentdb +/// - -/** The feed options and query methods.*/ -interface FeedOptions { - +/** The feed options and query methods. */ +interface FeedOptions extends RequestOptions { /** Max number of items to be returned in the enumeration operation. */ maxItemCount?: number; @@ -16,11 +15,13 @@ interface FeedOptions { /** Token for use with Session consistency. */ sessionToken?: string; + + /** Allow scan on the queries which couldn't be served as indexing was opted out on the requested paths. */ + enableScanInQuery?: boolean; } /** Options that can be specified for a request issued to the DocumentDB servers. */ interface RequestOptions { - /** Indicates what is the pre trigger to be invoked before the operation. */ preTriggerInclude?: string; @@ -29,26 +30,63 @@ interface RequestOptions { /** Conditions Associated with the request. */ accessCondition?: { - - /** Conditional HTTP method header type.*/ + /** Conditional HTTP method header type. */ type: string; - /** Conditional HTTP method header value.*/ + /** Conditional HTTP method header value. */ condition: string }; - /** Specifies indexing directives (index, do not index ..etc).*/ + /** Specifies indexing directives (index, do not index ..etc). */ indexingDirective?: string; /** Consistency level required by the client. */ consistencyLevel?: string; - /** Token for use with Session consistency.*/ + /** Token for use with Session consistency. */ sessionToken?: string; - /** Expiry time (in seconds) for resource token associated with permission (applicable only for requests on permissions).*/ + /** Expiry time (in seconds) for resource token associated with permission (applicable only for requests on permissions). */ resourceTokenExpirySeconds?: number; + /** Offer type when creating document collections. */ + offerType?: string; + + /** + * The user-specified throughput when creating document collections. + * + * Expressed in units of 100 request units per second. This can be between 400 and 250,000 (or higher by requesting a limit increase). + * + * If the x-ms-offer-throughput is over 10,000, then the collection must include a partitionKey definition. + * If the x-ms-offer-throughput is equal to or under 10,000, then the collection must not include a partitionKey definition. + * + * One of x-ms-offer-throughput or x-ms-offer-type must be specified. Both headers cannot be specified together. + */ + offerThroughput?: number; + + /** + * The partition key value for the requested document or attachment operation. + * + * Required for operations against documents and attachments when the collection definition includes a partition key definition. + */ + partitionKey?: string|string[]; + + /** + * Allow execution across multiple partitions + * + * If the collection is partitioned, this must be set to True unless the query filters against a single partition key + * or if the collection has only a single partition. + */ + enableCrossPartitionQuery?: boolean; + + /** If true, parallelize cross-partition queries */ + maxDegreeOfParallelism?: boolean; + + /** If true, populate quota in response */ + populateQuotaInfo?: boolean; +} + +interface DocumentOptions extends RequestOptions { /** Disables the automatic id generation. If id is missing in the body and this option is true, an error will be returned. */ disableAutomaticIdGeneration?: boolean; } @@ -73,49 +111,28 @@ interface SqlQuerySpec { /** Represents the error object returned from a failed query. */ interface QueryError { - /** The response code corresponding to the error. */ code: number; /** A string representing the error information. */ - body: string; // { code: string; message: string; }; + body: string; } -/** -* The callback to execute after the request execution. -* @param error - Will contain error information if an error occurs, undefined otherwise. -* @param resource - An object that represents the requested resource (Db, collection, document ... etc) if no error happens. -* @param responseHeaders - An object that contain the response headers. -*/ -interface RequestCallback { - (error: QueryError, resource: TResult, responseHeaders: any): void; -} - -/** Represents the result returned from a query. */ -interface QueryIterator { - current(): TResultRow; - executeNext(callback: (error: QueryError, result: TResultRow[], responseHeaders? : any) => void): void; - forEach(iteratorFunction : (error: QueryError, element: TResultRow, responseHeaders? : any) => void): void; - hasMoreResults(): boolean; - nextItem(callback: (error: QueryError, item: TResultRow, responseHeaders? : any) => void): void; - reset(): void; - toArray(callback: (error: QueryError, result: TResultRow[], responseHeaders? : any) => void): void -} +/** The callback to execute after the request execution. */ +type RequestCallback = (error: QueryError, resource: TResult, responseHeaders: any) => void; /** Reprents an object with a unique identifier. */ interface UniqueId { - /** The user-defined unique identifier for a document or other DocumentDB object (database, collection, procedure...) */ id: string; } /** Represents the common meta data for all DocumentDB objects. */ interface AbstractMeta extends UniqueId { - - /** The self link.*/ + /** The self link. */ _self: string; - /** The time the object was created.*/ + /** The time the object was created. */ _ts: string; _rid?: string; @@ -125,28 +142,26 @@ interface AbstractMeta extends UniqueId { } /** Represents a custom document for storing in DocumentDB */ -interface NewDocument extends UniqueId { +interface NewDocument extends UniqueId { + /** The time to live in seconds of the document. */ + ttl?: number; - /** A custom property for containing the actual JSON object representing the document. - * Define a custom property in order to disambiguate the JSON document from the metadata added by Azure. - * This property is optional and the name is application-specific. - */ - // doc: TContent; + /** Custom properties */ + [key: string]: any; } -/** Represents a document retrieved from storage. - * This differs from a new document by the properties in AbstractMeta, which are added by the system. - */ -interface RetrievedDocument extends NewDocument, AbstractMeta { - +/** Represents a document retrieved from storage. */ +interface RetrievedDocument extends NewDocument, AbstractMeta { } /** Represents the meta data for a database. */ +// tslint:disable-next-line:no-empty-interface interface DatabaseMeta extends AbstractMeta { } /** Represents the meta data for a collection. */ -interface CollectionMeta extends AbstractMeta { +// tslint:disable-next-line:no-empty-interface +interface CollectionMeta extends Collection, AbstractMeta { } /** Represents the meta data for a stored procedure. */ @@ -155,6 +170,7 @@ interface ProcedureMeta extends AbstractMeta { } /** Represents the meta data for a user-defined function. */ +// tslint:disable-next-line:no-empty-interface interface UserDefinedFunctionMeta extends AbstractMeta { } @@ -165,112 +181,478 @@ interface TriggerMeta extends AbstractMeta { triggerOperation: string; } -/** An object that is used for authenticating requests and must contains one of the options. */ -export interface AuthOptions { +/** A user-defined function may either be defined in string form or as a real function */ +export type UserFunction = ((...params: any[]) => void) | string; +interface UserScriptable extends UniqueId { + /** The user function. Must set one of body or serverscript */ + body?: UserFunction; + + /** The user function. Must set one of body or serverscript */ + serverScript?: UserFunction; +} + +/** An object that is used for authenticating requests and must contain one of the options. */ +export interface AuthOptions { /** The authorization master key to use to create the client. */ masterKey?: string; - /** An object that contains resources tokens. Keys for the object are resource Ids and values are the resource tokens.*/ - resourceTokens?: any; + /** An object that contains resources tokens. Keys for the object are resource Ids and values are the resource tokens. */ + resourceTokens?: {[key: string]: string}; /** An array of {@link Permission} objects. */ - permissionFeed?: any[]; + permissionFeed?: Permission[]; } /** Represents a DocumentDB stored procecedure. */ -export interface Procedure extends UniqueId { - - /** The function representing the stored procedure. */ - body(...params: any[]): void; +// tslint:disable-next-line:no-empty-interface +export interface Procedure extends UserScriptable { } /** Represents a DocumentDB user-defined function. */ -export interface UserDefinedFunction extends UniqueId { - - /** The function representing the user-defined function. */ - body(...params: any[]): void; +export interface UserDefinedFunction extends UserScriptable { + /** Type of function */ + userDefinedFunctionType?: UserDefinedFunctionType; } /** Represents a DocumentDB trigger. */ -export interface Trigger extends UniqueId { +export interface Trigger extends UserScriptable { /** The type of the trigger. Should be either 'pre' or 'post'. */ - triggerType: string; + triggerType?: TriggerType; /** The trigger operation. Should be one of 'all', 'create', 'update', 'delete', or 'replace'. */ - triggerOperation: string; - - /** The function representing the trigger. */ - body(...params: any[]): void; + triggerOperation: TriggerOperation; } /** Represents DocumentDB collection. */ export interface Collection extends UniqueId { - + /** The indexing policy associated with the collection. */ indexingPolicy?: IndexingPolicy; + + /** The default time to live in seconds for documents in a collection. */ + defaultTtl?: number; + + /** + * This value is used to configure the partition key to be used for partitioning data into multiple partitions. + * + * If the x-ms-offer-throughput is over 10,000, then the collection must include a partitionKey definition. + * + * If the x-ms-offer-throughput is equal to or under 10,000, then the collection must not include a partitionKey definition. + */ + partitionKey?: CollectionPartitionKey; } -/** The Indexing Path -*

Indexing paths hints to optimize indexing.
-* Indexing paths allow tradeoff between indexing storage and query performance -*

-*/ -interface IndexingPath { +/** Represents a DocumentDB attachment */ +export interface Attachment { + /** The MIME contentType of the attachment. */ + contentType: string; - /** The indexing type(range or hash) {@link IndexType}.*/ - IndexType: string; + /** Media link associated with the attachment content. */ + media: string; - /** Path to be indexed.*/ - Path: string; + /** Other properties */ + [name: string]: any; +} - /** Precision for this particular Index type for numeric data. */ - NumericPrecision: number; +export interface AttachmentMeta extends Attachment, AbstractMeta { +} - /** Precision for this particular Index type for string data. */ - StringPrecision: number; +export interface Permission extends UniqueId { + /** The mode of the permission */ + permissionMode: PermissionMode; + + /** The link of the resource that the permission will be applied to. */ + resource: string; +} + +export interface PermissionMeta extends Permission, AbstractMeta { } /** The Indexing Policy represents the indexing policy configuration for a collection. */ -interface IndexingPolicy { - - /** Specifies whether automatic indexing is enabled for a collection. -

In automatic indexing, documents can be explicitly excluded from indexing using {@link RequestOptions}. - In manual indexing, documents can be explicitly included.

*/ +export interface IndexingPolicy { + /** Specifies whether automatic indexing is enabled for a collection. */ automatic: boolean; /** The indexing mode (consistent or lazy) {@link IndexingMode}. */ - indexingMode: string; + indexingMode: IndexingMode; - /** An array of {@link IndexingPath} represents The paths to be incuded for indexing. */ - IncludedPaths: IndexingPath[]; + /** Represents the paths to be included for indexing. */ + IncludedPaths: IncludedPath[]; - /** An array of strings representing the paths to be excluded from indexing. */ - ExcludedPaths: string[]; + /** Represents the paths to be excluded from indexing. */ + ExcludedPaths: ExcludedPath[]; } -/** Provides a client-side logical representation of the Azure DocumentDB database account. This client is used to configure and execute requests against the service. - */ -export declare class DocumentClient { +interface ExcludedPath { + Path: string; +} + +interface IncludedPath { + /** Path to be indexed */ + Path: string; + Indexes: Index[]; +} + +/** Specifies the supported Index types. */ +interface Index { + Kind: IndexKind; + DataType: string; + Precision: number; +} + +/** ConnectionPolicy */ +export interface ConnectionPolicy { + /** Attachment content (aka media) download mode. */ + MediaReadMode: MediaReadMode; + + /** Time to wait for response from network peer for attachment content (aka media) operations. Represented in milliseconds. */ + MediaRequestTimeout: number; + + /** Request timeout (time to wait for response from network peer). Represented in milliseconds. */ + RequestTimeout: number; + + /** Flag to enable/disable automatic redirecting of requests based on read/write operations. */ + EnableEndpointDiscovery: boolean; + + /** List of azure regions to be used as preferred locations for read requests. */ + PreferredLocations: any[]; + + /** RetryOptions instance which defines several configurable properties used during retry. */ + RetryOptions: RetryOptions; + + /** + * Flag to disable SSL verification for the requests. + * + * SSL verification is enabled by default. Don't set this when targeting production endpoints. + * + * This is intended to be used only when targeting emulator endpoint to avoid failing your requests with SSL related error. + */ + DisableSSLVerification: boolean; +} + +/** RetryOptions */ +export interface RetryOptions { + /** Max number of retries to be performed for a request. Default value 9. */ + MaxRetryAttemptCount?: number; + + /** Fixed retry interval in milliseconds to wait between each retry ignoring the retryAfter returned as part of the response. */ + FixedRetryIntervalInMilliseconds?: number; + + /** Max wait time in seconds to wait for a request while the retries are happening. Default value 30 seconds. */ + MaxWaitTimeInSeconds?: number; +} + +export interface MediaOptions extends RequestOptions { + /** HTTP Slug header value. */ + slug?: string; + + /** HTTP ContentType header value. */ + contentType?: string; +} + +export interface DatabaseAccountRequestOptions extends RequestOptions { + /** The endpoint url whose database account needs to be retrieved. If not present, current client's url will be used. */ + urlConnection?: string; +} + +export interface DatabaseAccount { + DatabasesLink: string; + MediaLink: string; + MaxMediaStorageUsageInMB: number; + CurrentMediaStorageUsageInMB: number; + ConsistencyPolicy: ConsistencyPolicy; + WritableLocations: string[]; + ReadableLocations: string[]; +} + +export interface ConsistencyPolicy { + defaultConsistencyLevel: ConsistencyLevel; + maxStalenessPrefix: number; + maxStalenessIntervalInSeconds: number; +} + +export interface RangeOptions { + /** The low value in the range. */ + low: any; + + /** The high value in the range. */ + high: any; +} + +export interface PartitionKeyMap { + link: string; + range: Range; +} + +export interface CollectionPartitionKey { + /** + * An array of paths using which data within the collection can be partitioned. + * + * Paths must not contain a wildcard or a trailing slash. For example, the JSON property “AccountNumber” is specified as “/AccountNumber”. + * + * The array must contain only a single value. + */ + paths: string[]; + + /** + * The algorithm used for partitioning. Only Hash is supported. + */ + kind: PartitionKind; +} + +export type DocumentQuery = SqlQuerySpec | string; + +/** + * DEPRECATED + * + * Support for IPartitionResolver is now obsolete. + * It's recommended that you use Partitioned Collections for higher storage and throughput. + * @deprecated + */ +export interface PartitionResolver { + /** + * Extracts the partition key from the specified document using the partitionKeyExtractor + * @param document - The document from which to extract the partition key. + */ + getPartitionKey(document: any): string; + + /** + * Given a partition key, returns the correct collection link for creating a document. + * @param partitionKey - The partition key used to determine the target collection for create + */ + resolveForCreate(partitionKey: string): string; + + /** + * Given a partition key, returns a list of collection links to read from. + * @param partitionKey - The partition key used to determine the target collection for query + */ + resolveForRead(partitionKey: any): string[]; +} + +/** + * DEPRECATED + * + * Support for IPartitionResolver is now obsolete. + * It's recommended that you use Partitioned Collections for higher storage and throughput. + * @deprecated + */ +export interface ConsistentHashRingOptions { + /** Function to compute the hash for a given link or partition key */ + computeHash?(key: string|number, seed: number): number; + + /** Number of points in the ring to assign to each collection link */ + numberOfVirtualNodesPerCollection?: number; +} + +/** Represents a QueryIterator Object, an implmenetation of feed or query response that enables traversal and iterating over the response in the Azure DocumentDB database service. */ +export class QueryIterator { + /** + * Constructs a QueryIterator object + * @param documentclient - The documentclient object. + * @param query - A SQL query. + * @param options - Represents the feed options. + * @param fetchFunctions - A function to retrieve each page of data. An array of functions may be used to query more than one partition. + * @param resourceLinkopt - An optional parameter that represents the resourceLink (will be used in orderby/top/parallel query) + */ + constructor(documentclient: DocumentClient, query: DocumentQuery, options: FeedOptions, fetchFunctions: RequestCallback|Array>, resourceLinkopt?: string); + + /** + * Retrieve the current element on the QueryIterator. + * @param callback Function to execute for the current element. + */ + current(callback: RequestCallback): void; + + /** + * Retrieve the next batch of the feed and pass them as an array to a function + * @param callback Function execute on the feed response. + */ + executeNext(callback: RequestCallback): void; + + /** + * Execute a provided function once per feed element. + * @param callback Function to execute for each element. the function takes two parameters error, element. Note: the last element the callback + * will be called on will be undefined. If the callback explicitly returned false, the loop gets stopped. + */ + forEach(callback: RequestCallback): void; + + /** + * DEPRECATED + * + * Instead check if callback(undefined, undefined) is invoked by nextItem(callback) or current(callback) + * + * Determine if there are still remaining resources to processs based on the value of the continuation token + * or the elements remaining on the current batch in the QueryIterator. + * @deprecated + */ + hasMoreResults(): boolean; + + /** + * Execute a provided function on the next element in the QueryIterator. + * @param callback Function to execute for each element. + */ + nextItem(callback: RequestCallback): void; + + /** + * Reset the QueryIterator to the beginning and clear all the resources inside it + */ + reset(): void; + + /** + * Retrieve all the elements of the feed and pass them as an array to a function + * @param callback Function execute on the feed response. + */ + toArray(callback: RequestCallback): void; +} + +/** + * DEPRECATED + * + * Support for IPartitionResolver is now obsolete. + * It's recommended that you use Partitioned Collections for higher storage and throughput. + * @deprecated + */ +export class HashPartitionResolver implements PartitionResolver { + /** + * DEPRECATED + * + * Support for IPartitionResolver is now obsolete. + * It's recommended that you use Partitioned Collections for higher storage and throughput. + * + * @deprecated + * @param partitionKeyExtractor - If partitionKeyExtractor is a string, it should be the name of the property in the document to execute the hashing on. + * If partitionKeyExtractor is a function, it should be a function to extract the partition key from an object. + * @param collectionLink - Array of strings in the format 'dbs/foo/colls/bar' + * @param options - Options forr the ConsistentHashRing (MurmurHash) + */ + constructor(partitionKeyExtractor: string|((obj: any) => any), collectionLinks: string[], options?: ConsistentHashRingOptions); + + /** + * Extracts the partition key from the specified document using the partitionKeyExtractor + * @param document - The document from which to extract the partition key. + */ + getPartitionKey(document: any): string; + + /** + * Given a partition key, returns the correct collection link for creating a document. + * @param partitionKey - The partition key used to determine the target collection for create + */ + resolveForCreate(partitionKey: string): string; + + /** + * Given a partition key, returns a list of collection links to read from. + * @param partitionKey - The partition key used to determine the target collection for query + */ + resolveForRead(partitionKey: string): string[]; +} + +/** + * DEPRECATED + * + * Support for IPartitionResolver is now obsolete. + * It's recommended that you use Partitioned Collections for higher storage and throughput. + * + * @deprecated + */ +export class Range { + /** + * DEPRECATED + * + * Support for IPartitionResolver is now obsolete. + * It's recommended that you use Partitioned Collections for higher storage and throughput. + * + * @deprecated + * @param options - The Range constructor options. + */ + constructor(options: RangeOptions); +} + +/** + * DEPRECATED + * + * Support for IPartitionResolver is now obsolete. + * It's recommended that you use Partitioned Collections for higher storage and throughput. + * + * @deprecated + */ +export class RangePartitionResolver implements PartitionResolver { + /** + * DEPRECATED + * + * Support for IPartitionResolver is now obsolete. + * It's recommended that you use Partitioned Collections for higher storage and throughput. + * + * @deprecated + * @param partitionKeyExtractor - If partitionKeyExtractor is a string, it should be the name of the property in the document to execute the + * hashing on. If partitionKeyExtractor is a function, it should be a function to extract the partition key from an object. + * @param partitionKeyMap - The map from Range to collection link that is used for partitioning requests. + * @param [compareFunction] - Optional function that accepts two arguments a and b and returns a negative value if a < b, zero if a = b, or a positive value if a > b. + */ + constructor(partitionKeyExtractor: string|((obj: any) => any), partitionKeyMap: PartitionKeyMap[], compareFunction?: (a: any, b: any) => number); + + /** + * Extracts the partition key from the specified document using the partitionKeyExtractor + * @param document - The document from which to extract the partition key. + */ + getPartitionKey(document: any): string; + + /** + * Given a partition key, returns the correct collection link for creating a document. + * @param partitionKey - The partition key used to determine the target collection for create + */ + resolveForCreate(partitionKey: string): string; + + /** + * Given a partition key, returns a list of collection links to read from. + * @param partitionKey - The partition key used to determine the target collection for query + */ + resolveForRead(partitionKey: string): string[]; +} + +/** Provides a client-side logical representation of the Azure DocumentDB database account. This client is used to configure and execute requests against the service. */ +export class DocumentClient { /** * Constructs a DocumentClient. * @param urlConnection - The service endpoint to use to create the client. * @param auth - An object that is used for authenticating requests and must contains one of the options. * @param [connectionPolicy] - An instance of {@link ConnectionPolicy} class. This parameter is optional and the default connectionPolicy will be used if omitted. * @param [consistencyLevel] - An optional parameter that represents the consistency level. It can take any value from {@link ConsistencyLevel}. - */ - constructor(urlConnection: string, auth: AuthOptions, connectionPolicy?: any, consistencyLevel?: string); + */ + constructor(urlConnection: string, auth: AuthOptions, connectionPolicy?: ConnectionPolicy, consistencyLevel?: ConsistencyLevel); - /** Send a request for creating a database. + /** Create an attachment for the document object. *

- * A database manages users, permissions and a set of collections.
- * Each Azure DocumentDB Database Account is able to support multiple independent named databases, with the database being the logical container for data.
- * Each Database consists of one or more collections, each of which in turn contain one or more documents. Since databases are an an administrative resource, the Service Master Key will be required in order to access and successfully complete any action using the User APIs.
+ * Each document may contain zero or more attachments. Attachments can be of any MIME type - text, image, binary data.
+ * These are stored externally in Azure Blob storage. Attachments are automatically deleted when the parent document is deleted. *

+ * @param documentLink - The self-link of the document. + * @param body - The metadata the defines the attachment media like media, contentType. It can include any other properties as part of the metedata + * @param [options] - The request options. + * @param callback - The callback for the request. + */ + createAttachment(documentLink: string, body: Attachment, options: RequestOptions, callback: RequestCallback): void; + createAttachment(documentLink: string, body: Attachment, callback: RequestCallback): void; + + /** + * Create an attachment with media file for the document object. + * @param documentLink - The self-link of the document. + * @param readableStream - The stream that represents the media itself that needs to be uploaded. + * @param [options] - The request options. + * @param callback - The callback for the request. + */ + createAttachmentAndUploadMedia(documentLink: string, readableStream: NodeJS.ReadableStream, options: MediaOptions, callback: RequestCallback): void; + createAttachmentAndUploadMedia(documentLink: string, readableStream: NodeJS.ReadableStream, callback: RequestCallback): void; + + /** Send a request for creating a database. + * A database manages users, permissions and a set of collections. + * Each Azure DocumentDB Database Account is able to support multiple independent named databases, with the database being the logical container for data. + * Each Database consists of one or more collections, each of which in turn contain one or more documents. Since databases are an an administrative + * resource, the Service Master Key will be required in order to access and successfully complete any action using the User APIs. * @param body - A json object that represents The database to be created. * @param [options] - The request options. * @param callback - The callback for the request. - */ - public createDatabase(body: UniqueId, options: RequestOptions, callback: RequestCallback): void; + */ + createDatabase(body: UniqueId, options: RequestOptions, callback: RequestCallback): void; + createDatabase(body: UniqueId, callback: RequestCallback): void; /** * Creates a collection. @@ -285,21 +667,23 @@ export declare class DocumentClient { * @param [options] - The request options. * @param callback - The callback for the request. */ - public createCollection(databaseLink: string, body: Collection, options: RequestOptions, callback: RequestCallback): void; + createCollection(databaseLink: string, body: Collection, options: RequestOptions, callback: RequestCallback): void; + createCollection(databaseLink: string, body: Collection, callback: RequestCallback): void; /** * Create a StoredProcedure. *

* DocumentDB allows stored procedures to be executed in the storage tier, directly against a document collection. The script
* gets executed under ACID transactions on the primary storage partition of the specified collection. For additional details,
- * refer to the server-side JavaScript API documentation. + * refer to the server-side JavaScript API documentation. *

* @param collectionLink - The self-link of the collection. * @param procedure - Represents the body of the stored procedure. * @param [options] - The request options. * @param callback - The callback for the request. */ - public createStoredProcedure(collectionLink: string, procedure: Procedure, options: RequestOptions, callback: RequestCallback): void; + createStoredProcedure(collectionLink: string, procedure: Procedure, options: RequestOptions, callback: RequestCallback): void; + createStoredProcedure(collectionLink: string, procedure: Procedure, callback: RequestCallback): void; /** * Create a UserDefinedFunction. @@ -312,7 +696,8 @@ export declare class DocumentClient { * @param [options] - The request options. * @param callback - The callback for the request. */ - public createUserDefinedFunction(collectionLink: string, udf: UserDefinedFunction, options: RequestOptions, callback: RequestCallback): void; + createUserDefinedFunction(collectionLink: string, udf: UserDefinedFunction, options: RequestOptions, callback: RequestCallback): void; + createUserDefinedFunction(collectionLink: string, udf: UserDefinedFunction, callback: RequestCallback): void; /** * Create a trigger. @@ -325,35 +710,59 @@ export declare class DocumentClient { * @param [options] - The request options. * @param callback - The callback for the request. */ - public createTrigger(collectionLink: string, trigger: Trigger, options: RequestOptions, callback: RequestCallback): void; + createTrigger(collectionLink: string, trigger: Trigger, options: RequestOptions, callback: RequestCallback): void; + createTrigger(collectionLink: string, trigger: Trigger, callback: RequestCallback): void; /** * Create a document. - *

+ *

* There is no set schema for JSON documents. They may contain any number of custom properties as well as an optional list of attachments.
* A Document is an application resource and can be authorized using the master key or resource keys *

- * @param collectionLink - The self-link of the collection. + * @param documentsFeedOrDatabaseLink - The self-link of the collection. * @param document - Represents the body of the document. Can contain any number of user defined properties. * @param [options] - The request options. * @param callback - The callback for the request. */ - public createDocument(collectionSelfLink: string, document: NewDocument, options: RequestOptions, callback: RequestCallback>): void; + createDocument(documentsFeedOrDatabaseLink: string, document: NewDocument, options: DocumentOptions, callback: RequestCallback): void; + createDocument(documentsFeedOrDatabaseLink: string, document: NewDocument, callback: RequestCallback): void; + + /** + * Create a permission. A permission represents a per-User Permission to access a specific resource e.g. Document or Collection. + * @param userLink - Self-link of the user. + * @param body - Permission body + * @param options - Request options + * @param callback - Callback for the request + */ + createPermission(userLink: string, body: Permission, options: RequestOptions, callback: RequestCallback): void; + createPermission(userLink: string, body: Permission, callback: RequestCallback): void; + + /** + * Create a user + * @param databaseLink - The self-link of the database. + * @param body - Represents the body of the user. + * @param options - The request options. + * @param callback - The callback for the request. + */ + createUser(databaseLink: string, body: UniqueId, options: RequestOptions, callback: RequestCallback): void; + createUser(databaseLink: string, body: UniqueId, callback: RequestCallback): void; /** * Execute the StoredProcedure represented by the object. * @param procedureLink - The self-link of the stored procedure. * @param [params] - Represents the parameters of the stored procedure. + * @param options - The request options * @param callback - The callback for the request. */ - public executeStoredProcedure(procedureLink: string, params: any[], callback: RequestCallback): void; + executeStoredProcedure(procedureLink: string, params: any[], options: RequestOptions, callback: RequestCallback): void; + executeStoredProcedure(procedureLink: string, paramsOrOptions: any[] | RequestOptions, callback: RequestCallback): void; - /** Lists all databases that satisfy a query. + /** Lists all databases that satisfy a query. * @param query - A SQL query string. * @param [options] - The feed options. * @returns - An instance of QueryIterator to handle reading feed. */ - public queryDatabases(query: string | SqlQuerySpec): QueryIterator; + queryDatabases(query: DocumentQuery, options?: FeedOptions): QueryIterator; /** * Query the collections for the database. @@ -362,7 +771,7 @@ export declare class DocumentClient { * @param [options] - Represents the feed options. * @returns - An instance of queryIterator to handle reading feed. */ - public queryCollections(databaseLink: string, query: string | SqlQuerySpec): QueryIterator; + queryCollections(databaseLink: string, query: DocumentQuery, options?: FeedOptions): QueryIterator; /** * Query the storedProcedures for the collection. @@ -371,7 +780,7 @@ export declare class DocumentClient { * @param [options] - Represents the feed options. * @returns - An instance of queryIterator to handle reading feed. */ - public queryStoredProcedures(collectionLink: string, query: string | SqlQuerySpec): QueryIterator; + queryStoredProcedures(collectionLink: string, query: DocumentQuery, options?: FeedOptions): QueryIterator; /** * Query the user-defined functions for the collection. @@ -380,16 +789,16 @@ export declare class DocumentClient { * @param [options] - Represents the feed options. * @returns - An instance of queryIterator to handle reading feed. */ - public queryUserDefinedFunctions(collectionLink: string, query: string | SqlQuerySpec, options?: FeedOptions): QueryIterator; + queryUserDefinedFunctions(collectionLink: string, query: DocumentQuery, options?: FeedOptions): QueryIterator; /** - * Query the documents for the collection. - * @param collectionLink - The self-link of the collection. - * @param query - A SQL query string. - * @param [options] - Represents the feed options. - * @returns - An instance of queryIterator to handle reading feed. - */ - public queryDocuments(collectionLink: string, query: string | SqlQuerySpec, options?: FeedOptions): QueryIterator>; + * Query the documents for the collection. + * @param collectionLink - The self-link of the collection. + * @param query - A SQL query string. + * @param [options] - Represents the feed options. + * @returns - An instance of queryIterator to handle reading feed. + */ + queryDocuments(collectionLink: string, query: DocumentQuery, options?: FeedOptions): QueryIterator; /** * Query the triggers for the collection. @@ -398,39 +807,136 @@ export declare class DocumentClient { * @param {FeedOptions} [options] - Represents the feed options. * @returns {QueryIterator} - An instance of queryIterator to handle reading feed. */ - public queryTriggers(collectionLink: string, query: string | SqlQuerySpec, options?: FeedOptions): QueryIterator; + queryTriggers(collectionLink: string, query: DocumentQuery, options?: FeedOptions): QueryIterator; + + /** + * Query the attachments for the document. + * @param documentLink - The self-link of the document. + * @param query - A SQL query. + * @param [options] - Represents the feed options. + */ + queryAttachments(documentLink: string, query: DocumentQuery, options?: FeedOptions): QueryIterator; + + /** + * Query the conflicts for the collection. + * @param collectionLink - The self-link of the collection. + * @param query - A SQL query. + * @param [options] - Represents the feed options. + */ + queryConflicts(collectionLink: string, query: DocumentQuery, options?: FeedOptions): QueryIterator; + + /** + * Lists all offers that satisfy a query. + * @param query - A SQL query. + * @param options - The feed options. + */ + queryOffers(query: DocumentQuery, options?: FeedOptions): QueryIterator; + + /** + * Query the permission for the user. + * @param userLink - The self-link of the user. + * @param query - A SQL query. + * @param options - Feed options. + */ + queryPermissions(userLink: string, query: DocumentQuery, options?: FeedOptions): QueryIterator; + + /** + * Query the users for the database. + * @param databaseLink - The self-link of the database. + * @param query - A SQL query. + * @param options - Represents the feed options. + */ + queryUsers(databaseLink: string, query: DocumentQuery, options?: FeedOptions): QueryIterator; /** * Delete the document object. * @param documentLink - The self-link of the document. * @param [options] - The request options. - * @param callback - The callback for the request. - */ - public deleteDocument(documentLink: string, options: RequestOptions, callback: RequestCallback): void; + * @param callback - The callback for the request. + */ + deleteDocument(documentLink: string, options: RequestOptions, callback: RequestCallback): void; + deleteDocument(documentLink: string, callback: RequestCallback): void; /** * Delete the database object. * @param databaseLink - The self-link of the database. * @param [options] - The request options. - * @param callback - The callback for the request. - */ - public deleteDatabase(databaseLink: string, options: RequestOptions, callback: RequestCallback): void; + * @param callback - The callback for the request. + */ + deleteDatabase(databaseLink: string, options: RequestOptions, callback: RequestCallback): void; + deleteDatabase(databaseLink: string, callback: RequestCallback): void; /** * Delete the collection object. * @param collectionLink - The self-link of the collection. * @param [options] - The request options. - * @param callback - The callback for the request. - */ - public deleteCollection(collectionLink: string, options: RequestOptions, callback: RequestCallback): void; + * @param callback - The callback for the request. + */ + deleteCollection(collectionLink: string, options: RequestOptions, callback: RequestCallback): void; + deleteCollection(collectionLink: string, callback: RequestCallback): void; /** * Delete the StoredProcedure object. * @param procedureLink - The self-link of the stored procedure. * @param [options] - The request options. * @param callback - The callback for the request. - */ - public deleteStoredProcedure(procedureLink: string, options: RequestOptions, callback: RequestCallback): void; + */ + deleteStoredProcedure(procedureLink: string, options: RequestOptions, callback: RequestCallback): void; + deleteStoredProcedure(procedureLink: string, callback: RequestCallback): void; + + /** + * Delete an attachment + * @param attachmentLink - The self-link of the attachment. + * @param options - The request options. + * @param callback - The callback for the request. + */ + deleteAttachment(attachmentLink: string, options: RequestOptions, callback: RequestCallback): void; + deleteAttachment(attachmentLink: string, callback: RequestCallback): void; + + /** + * Delete a conflict + * @param conflictLink - The self-link of the conflict. + * @param options - The request options. + * @param callback - The callback for the request. + */ + deleteConflict(conflictLink: string, options: RequestOptions, callback: RequestCallback): void; + deleteConflict(conflictLink: string, callback: RequestCallback): void; + + /** + * Delete a permission + * @param permissionLink - The self-link of the permission. + * @param options - The request options. + * @param callback - The callback for the request. + */ + deletePermission(permissionLink: string, options: RequestOptions, callback: RequestCallback): void; + deletePermission(permissionLink: string, callback: RequestCallback): void; + + /** + * Delete a trigger + * @param triggerLink - The self-link of the trigger. + * @param options - The request options. + * @param callback - The callback for the request. + */ + deleteTrigger(triggerLink: string, options: RequestOptions, callback: RequestCallback): void; + deleteTrigger(triggerLink: string, callback: RequestCallback): void; + + /** + * Delete a user + * @param userLink - The self-link of the user. + * @param options - The request options. + * @param callback - The callback for the request. + */ + deleteUser(userLink: string, options: RequestOptions, callback: RequestCallback): void; + deleteUser(userLink: string, callback: RequestCallback): void; + + /** + * Delete a user-defined function + * @param udfLink - The self-link of the user defined function. + * @param options - The request options. + * @param callback - The callback for the request. + */ + deleteUserDefinedFunction(udfLink: string, options: RequestOptions, callback: RequestCallback): void; + deleteUserDefinedFunction(udfLink: string, callback: RequestCallback): void; /** * Replace the document object. @@ -439,7 +945,8 @@ export declare class DocumentClient { * @param {RequestOptions} [options] - The request options. * @param {RequestCallback} callback - The callback for the request. */ - public replaceDocument(documentLink: string, document: NewDocument, options: RequestOptions, callback: RequestCallback>): void; + replaceDocument(documentLink: string, document: NewDocument, options: RequestOptions, callback: RequestCallback): void; + replaceDocument(documentLink: string, document: NewDocument, callback: RequestCallback): void; /** * Replace the StoredProcedure object. @@ -448,5 +955,397 @@ export declare class DocumentClient { * @param [options] - The request options. * @param callback - The callback for the request. */ - public replaceStoredProcedure(procedureLink: string, procedure: Procedure, options: RequestOptions, callback: RequestCallback): void; + replaceStoredProcedure(procedureLink: string, procedure: Procedure, options: RequestOptions, callback: RequestCallback): void; + replaceStoredProcedure(procedureLink: string, procedure: Procedure, callback: RequestCallback): void; + + /** + * Replace the attachment object. + * @param attachmentLink - The self-link of the attachment. + * @param attachment - Represent the new attachment body. + * @param options - The request options. + * @param callback - The callback for the request. + */ + replaceAttachment(attachmentLink: string, attachment: Attachment, options: RequestOptions, callback: RequestCallback): void; + replaceAttachment(attachmentLink: string, attachment: Attachment, callback: RequestCallback): void; + + /** + * Replace the document collection. + * @param collectionLink - The self-link of the document collection. + * @param collection - Represent the new document collection body. + * @param options - The request options. + * @param callback - The callback for the request. + */ + replaceCollection(collectionLink: string, collection: Collection, options: RequestOptions, callback: RequestCallback): void; + replaceCollection(collectionLink: string, collection: Collection, callback: RequestCallback): void; + + /** + * Replace the offer object. + * @param offerLink - The self-link of the offer. + * @param offer - Represent the new offer body. + * @param callback - The callback for the request. + */ + replaceOffer(offerLink: string, offer: any, callback: RequestCallback): void; + + /** + * Replace the permission object. + * @param permissionLink - The self-link of the permission. + * @param permission - Represent the new permission body. + * @param options - The request options. + * @param callback - The callback for the request. + */ + replacePermission(permissionLink: string, permission: Permission, options: RequestOptions, callback: RequestCallback): void; + replacePermission(permissionLink: string, permission: Permission, callback: RequestCallback): void; + + /** + * Replace the trigger object. + * @param triggerLink - The self-link of the trigger. + * @param trigger - Represent the new trigger body. + * @param options - The request options. + * @param callback - The callback for the request. + */ + replaceTrigger(triggerLink: string, trigger: Trigger, options: RequestOptions, callback: RequestCallback): void; + replaceTrigger(triggerLink: string, trigger: Trigger, callback: RequestCallback): void; + + /** + * Replace the user object. + * @param userLink - The self-link of the user. + * @param user - Represent the new user body. + * @param options - The request options. + * @param callback - The callback for the request. + */ + replaceUser(userLink: string, user: UniqueId, options: RequestOptions, callback: RequestCallback): void; + replaceUser(userLink: string, user: UniqueId, callback: RequestCallback): void; + + /** + * Replace the UserDefinedFunction object. + * @param udfLink - The self-link of the user defined function. + * @param udf - Represent the new udf body. + * @param options - The request options. + * @param callback - The callback for the request. + */ + replaceUserDefinedFunction(udfLink: string, udf: UserDefinedFunction, options: RequestOptions, callback: RequestCallback): void; + replaceUserDefinedFunction(udfLink: string, udf: UserDefinedFunction, callback: RequestCallback): void; + + /** + * Read an Attachment object. + * @param attachmentLink - The self-link of the attachment. + * @param options - The request options. + * @param callback - The callback for the request. + */ + readAttachment(attachmentLink: string, options: RequestOptions, callback: RequestCallback): void; + readAttachment(attachmentLink: string, callback: RequestCallback): void; + + /** + * Get all attachments for this document. + * @param documentLink - The self-link of the document. + * @param options - The feed options. + */ + readAttachments(documentLink: string, options?: FeedOptions): QueryIterator; + + /** + * Read a collection. + * @param collectionLink - The self-link of the collection. + * @param options - The request options. + * @param callback - The callback for the request. + */ + readCollection(collectionLink: string, options: RequestOptions, callback: RequestCallback): void; + readCollection(collectionLink: string, callback: RequestCallback): void; + + /** + * Get all collections in this database. + * @param databaseLink - The self-link of the database. + * @param options - The feed options. + */ + readCollections(databaseLink: string, options?: FeedOptions): QueryIterator; + + /** + * Read a conflict. + * @param conflictLink - The self-link of the conflict. + * @param options - The request options. + * @param callback - The callback for the request. + */ + readConflict(conflictLink: string, options: RequestOptions, callback: RequestCallback): void; + readConflict(conflictLink: string, callback: RequestCallback): void; + + /** + * Get all conflicts in this collection. + * @param collectionLink - The self-link of the collection. + * @param options - The feed options. + */ + readConflicts(collectionLink: string, options?: FeedOptions): QueryIterator; + + /** + * Read a database. + * @param databaseLink - The self-link of the database. + * @param options - The request options. + * @param callback - The callback for the request. + */ + readDatabase(databaseLink: string, options: RequestOptions, callback: RequestCallback): void; + readDatabase(databaseLink: string, callback: RequestCallback): void; + + /** + * List all databases. + * @param options - The request options. + */ + readDatabases(options?: FeedOptions): QueryIterator; + + /** + * Read a document. + * @param documentLink - The self-link of the document. + * @param options - The request options. + * @param callback - The callback for the request. + */ + readDocument(documentLink: string, options: RequestOptions, callback: RequestCallback): void; + readDocument(documentLink: string, callback: RequestCallback): void; + + /** + * Get all documents in this collection. + * @param collectionLink - The self-link of the collection. + * @param options - The feed options. + */ + readDocuments(collectionLink: string, options?: FeedOptions): QueryIterator; + + /** + * Read the media for the attachment object. + * @param mediaLink - The media link of the media in the attachment. + * @param callback - The callback for the request, the result parameter can be a buffer or a stream depending on the value of MediaReadMode + */ + readMedia(mediaLink: string, callback: RequestCallback): void; + + /** + * Read an offer. + * @param offerLink - The self-link of the offer. + * @param callback - The callback for the request. + */ + readOffer(offerLink: string, callback: RequestCallback): void; + + /** + * List all offers + * @param options - The feed options. + */ + readOffers(options?: FeedOptions): QueryIterator; + + /** + * Read a permission. + * @param permissionLink - The self-link of the permission. + * @param options - The request options. + * @param callback - The callback for the request. + */ + readPermission(permissionLink: string, options: RequestOptions, callback: RequestCallback): void; + readPermission(permissionLink: string, callback: RequestCallback): void; + + /** + * Get all permissions for this user. + * @param userLink - The self-link of the user. + * @param feedOptions - The feed options + */ + readPermissions(userLink: string, feedOptions?: FeedOptions): QueryIterator; + + /** + * Read a stored procedure + * @param sprocLink - The self-link of the stored procedure. + * @param options - The request options. + * @param callback - The callback for the request. + */ + readStoredProcedure(sprocLink: string, options: RequestOptions, callback: RequestCallback): void; + readStoredProcedure(sprocLink: string, callback: RequestCallback): void; + + /** + * Get all StoredProcedures in this collection. + * @param collectionLink - The self-link of the collection. + * @param options - The feed options. + */ + readStoredProcedures(collectionLink: string, options?: RequestOptions): QueryIterator; + + /** + * Reads a trigger object. + * @param triggerLink - The self-link of the trigger. + * @param options - The request options. + * @param callback - The callback for the request. + */ + readTrigger(triggerLink: string, options: RequestOptions, callback: RequestCallback): void; + readTrigger(triggerLink: string, callback: RequestCallback): void; + + /** + * Get all triggers in this collection. + * @param collectionLink - The self-link of the collection. + * @param options - The feed options. + */ + readTriggers(collectionLink: string, options?: FeedOptions): QueryIterator; + + /** + * Reads a user. + * @param userLink - The self-link of the user. + * @param options - The request options. + * @param callback - The callback for the request. + */ + readUser(userLink: string, options: RequestOptions, callback: RequestCallback): void; + readUser(userLink: string, callback: RequestCallback): void; + + /** + * Reads a udf object. + * @param udfLink - The self-link of the user defined function. + * @param options - The request options. + * @param callback - The callback for the request. + */ + readUserDefinedFunction(udfLink: string, options: RequestOptions, callback: RequestCallback): void; + readUserDefinedFunction(udfLink: string, callback: RequestCallback): void; + + /** + * Get all UserDefinedFunctions in this collection. + * @param collectionLink - The self-link of the collection. + * @param options - The feed options. + */ + readUserDefinedFunctions(collectionLink: string, options?: FeedOptions): QueryIterator; + + /** + * Get all users in this database. + * @param databaseLink - The self-link of the database. + * @param feedOptions - The feed options. + */ + readUsers(databaseLink: string, feedOptions?: FeedOptions): QueryIterator; + + /** + * Update media for the attachment + * @param mediaLink - The media link of the media in the attachment. + * @param readableStream - The stream that represents the media itself that needs to be uploaded. + * @param options - options for the media + * @param callback - The callback for the request. + */ + updateMedia(mediaLink: string, readableStream: NodeJS.ReadableStream, options: MediaOptions, callback: RequestCallback): void; + updateMedia(mediaLink: string, readableStream: NodeJS.ReadableStream, callback: RequestCallback): void; + + /** + * Upsert an attachment for the document object. + *

+ * Each document may contain zero or more attachments. Attachments can be of any MIME type - text, image, binary data. + * These are stored externally in Azure Blob storage. Attachments are automatically deleted when the parent document is deleted. + *

+ * @param documentLink - The self-link of the document. + * @param body - The metadata the defines the attachment media like media, contentType. It can include any other properties as part of the metedata. + * @param options - The request options. + * @param callback - The callback for the request. + */ + upsertAttachment(documentLink: string, body: Attachment, options: RequestOptions, callback: RequestCallback): void; + upsertAttachment(documentLink: string, body: Attachment, callback: RequestCallback): void; + + /** + * Upsert an attachment for the document object. + * @param documentLink - The self-link of the document. + * @param readableStream - the stream that represents the media itself that needs to be uploaded. + * @param options - The request options. + * @param callback - The callback for the request. + */ + upsertAttachmentAndUploadMedia(documentLink: string, readableStream: NodeJS.ReadableStream, options: MediaOptions, callback: RequestCallback): void; + upsertAttachmentAndUploadMedia(documentLink: string, readableStream: NodeJS.ReadableStream, callback: RequestCallback): void; + + /** + * Upsert a document. + *

+ * There is no set schema for JSON documents. They may contain any number of custom properties as well as an optional list of attachments. + * A Document is an application resource and can be authorized using the master key or resource keys + *

+ * @param documentsFeedOrDatabaseLink - The collection link or database link if using a partition resolver + * @param body - Represents the body of the document. Can contain any number of user defined properties. + * @param options - The request options. + * @param callback - The callback for the request. + */ + upsertDocument(documentsFeedOrDatabaseLink: string, body: NewDocument, options: DocumentOptions, callback: RequestCallback): void; + upsertDocument(documentsFeedOrDatabaseLink: string, body: NewDocument, callback: RequestCallback): void; + + /** + * Upsert a permission. + *

+ * A permission represents a per-User Permission to access a specific resource e.g. Document or Collection. + *

+ * @param userLink - The self-link of the user. + * @param body - Represents the body of the permission. + * @param options - The request options. + * @param callback - The callback for the request. + */ + upsertPermission(userLink: string, body: Permission, options: RequestOptions, callback: RequestCallback): void; + upsertPermission(userLink: string, body: Permission, callback: RequestCallback): void; + + /** + * Upsert a StoredProcedure. + *

+ * DocumentDB allows stored procedures to be executed in the storage tier, directly against a document collection. The script + * gets executed under ACID transactions on the primary storage partition of the specified collection. For additional details, + * refer to the server-side JavaScript API documentation. + *

+ * @param collectionLink - The self-link of the collection. + * @param sproc - Represents the body of the stored procedure. + * @param options - The request options. + * @param callback - The callback for the request. + */ + upsertStoredProcedure(collectionLink: string, sproc: Procedure, options: RequestOptions, callback: RequestCallback): void; + upsertStoredProcedure(collectionLink: string, sproc: Procedure, callback: RequestCallback): void; + + /** + * Upsert a trigger. + *

+ * DocumentDB supports pre and post triggers defined in JavaScript to be executed on creates, updates and deletes. + * For additional details, refer to the server-side JavaScript API documentation. + *

+ * @param collectionLink - The self-link of the collection. + * @param trigger - Represents the body of the trigger. + * @param options - The request options. + * @param callback - The callback for the request. + */ + upsertTrigger(collectionLink: string, trigger: Trigger, options: RequestOptions, callback: RequestCallback): void; + upsertTrigger(collectionLink: string, trigger: Trigger, callback: RequestCallback): void; + + /** + * Upsert a database user. + * @param databaseLink - The self-link of the database. + * @param body - Represents the body of the user. + * @param options - The request options. + * @param callback - The callback for the request. + */ + upsertUser(databaseLink: string, body: UniqueId, options: RequestOptions, callback: RequestCallback): void; + upsertUser(databaseLink: string, body: UniqueId, callback: RequestCallback): void; + + /** + * Upsert a UserDefinedFunction. + *

+ * DocumentDB supports JavaScript UDFs which can be used inside queries, stored procedures and triggers. + * For additional details, refer to the server-side JavaScript API documentation. + *

+ * @param collectionLink - The self-link of the collection. + * @param udf - Represents the body of the userDefinedFunction. + * @param options - The request options. + * @param callback - The callback for the request. + */ + upsertUserDefinedFunction(collectionLink: string, udf: UserDefinedFunction, options: RequestOptions, callback: RequestCallback): void; + upsertUserDefinedFunction(collectionLink: string, udf: UserDefinedFunction, callback: RequestCallback): void; + + /** + * Gets the Database account information. + * @param options - The request options + * @param callback - The callback for the request + */ + getDatabaseAccount(options: DatabaseAccountRequestOptions, callback: RequestCallback): void; + getDatabaseAccount(callback: RequestCallback): void; + + /** + * Gets the curent read endpoint for a geo-replicated database account. + * @param callback - The callback for the request + */ + getReadEndpoint(callback: RequestCallback): void; + + /** + * Gets the curent write endpoint for a geo-replicated database account. + * @param callback - The callback for the request + */ + getWriteEndpoint(callback: RequestCallback): void; } + +export type MediaReadMode = 'Buffered' | 'Streamed'; +export type ConsistencyLevel = 'Strong' | 'BoundedStaleness' | 'Session' | 'Eventual'; +export type IndexingMode = 'Consistent' | 'Lazy'; +export type IndexKind = 'Hash' | 'Range' | 'Spatial'; +export type PermissionMode = 'None' | 'Read' | 'All'; +export type TriggerType = 'Pre' | 'Post' | 'pre' | 'post'; +export type TriggerOperation = 'All' | 'Create' | 'Update' | 'Delete' | 'Replace' | 'all' | 'create' | 'update' | 'delete' | 'replace'; +export type UserDefinedFunctionType = 'Javascript'; +export type PartitionKind = 'Hash'; diff --git a/types/documentdb/tsconfig.json b/types/documentdb/tsconfig.json index 552149e7db..0f1d4e70e9 100644 --- a/types/documentdb/tsconfig.json +++ b/types/documentdb/tsconfig.json @@ -11,8 +11,8 @@ "baseUrl": "../", "typeRoots": [ "../" - ], - "types": [], + ], + "types": [ ], "noEmit": true, "forceConsistentCasingInFileNames": true }, diff --git a/types/documentdb/tslint.json b/types/documentdb/tslint.json new file mode 100644 index 0000000000..2221e40e4a --- /dev/null +++ b/types/documentdb/tslint.json @@ -0,0 +1 @@ +{ "extends": "../tslint.json" } \ No newline at end of file