@azure/cosmos has moved to a new repo https://github.com/Azure/azure-sdk-for-js
Перейти к файлу
Christopher Anderson 0d38b3873b
Feature/object model refactor (#26)
* Move foreach to async iterator

* Mock out new APIs

* remove legacy tests

* remove old ntvs stuff for samples

* Add shimmed implemention + bug fixes

* Update (some) samples to use new OM

* refactor interfaces into their own files

* refactor om into new directory structure

* small tweak to lib in gitignore

* renamed document to item

* update tests

* Move Item/Permission/User tests

* Remove Attachment from OM

* Update item, container, database, and database account tests

* Permission tests

* User tests

* Aggregate query tests moved to new OM

* collectionNaming tests obsolete due to attachment/media

* Update crosspartition test

* Add encoding test

* Update incremental feed tests

* update proxy test

* Update query test

* update ruPerMind test

* Update session tests

* Update session container tests (moved to unit test)

* Update SSL tests

* Update UriFactory tests (moved to unit)

* Update document client tests

* Update authorization tests

* Fix lint

* Refactor of UDF test

* Refactor trigger test

* Refactor functional TTL test

* Remove UriFactory

* Type assertion due to intermediate implementation details

* Query needs to support string

* Support any overload

* Query e2e tests

* Spatial e2e test updated

* Refactor functional sproc test

* Add await to fix TS errors

* Type assertion on container def for now

* Remove offer tests for now

* authorization tests updated

* bug in test

* Comment out and skip HashPartitionResolver test

* Use UriFactory for urls

* rids make me sad

* types are fun

* bugs in permission test

* Symbol Shim for forEach

* Fix user test

* stringify the funciton bodys to avoid TypeScript weirdness

* Support string body for UDF

* Small bug in TTL test

* Fix Authorization tests

* remove bad options object

* One more sproc fix

* Need a blank object for parition key (if none specified)

* One tests is broken still for now

* Expose ErrorResponse

* Handle undefined in forEach

* Better error handling

* Better error handling for crossParititon tests

* Update tslint to catch dangling promises

* Port over existing docs to TS files

* Fix Mock toArray to promise based

* Include tests in lint and fix errors

* No assignment to Symbol.asyncIterator in node 10

* tslint fix

* Remove unnecessary test (forEach is an iterable now)

* no more generic database names in test

* Index kind mistake

* Missing promise

* Shorten timeout (flakey test)

* rename \w+s\.read to \w+s\.readAll

* Move all #.get\w+ to #.get

* Remove rid test. Pick up global timeout in auth test

* Fix tslint

* Fix test timeouts against production, except for TTL. Run TS tests directly

* Add files

* remove some collection/document mentions

* fix sproc mistake from rename

* Add CosmosClientOptions to export
2018-06-29 16:51:57 -07:00
.vscode Feature/object model refactor (#26) 2018-06-29 16:51:57 -07:00
samples Feature/object model refactor (#26) 2018-06-29 16:51:57 -07:00
src Feature/object model refactor (#26) 2018-06-29 16:51:57 -07:00
.editorConfig Added an editorConfig 2017-01-18 12:56:28 +01:00
.gitattributes adding .git* 2014-08-26 08:25:08 -07:00
.gitignore Feature/object model refactor (#26) 2018-06-29 16:51:57 -07:00
.npmignore Package info clean up (#12) 2018-06-29 14:27:23 -07:00
Contributing.md Node.js SDK Release 1.7.0 2016-04-26 13:21:42 -07:00
LICENSE TypeScript conversion (#3) 2018-06-04 14:03:49 -07:00
README.md Package info clean up (#12) 2018-06-29 14:27:23 -07:00
SDK + Samples Workspace.code-workspace TypeScript conversion (#3) 2018-06-04 14:03:49 -07:00
browser-test.js TypeScript conversion (#3) 2018-06-04 14:03:49 -07:00
changelog.md Port Version 1.14.4 release (#8) 2018-06-29 14:26:53 -07:00
dev.md TypeScript conversion (#3) 2018-06-04 14:03:49 -07:00
karma.config.js TypeScript conversion (#3) 2018-06-04 14:03:49 -07:00
package-lock.json Feature/object model refactor (#26) 2018-06-29 16:51:57 -07:00
package.json Feature/object model refactor (#26) 2018-06-29 16:51:57 -07:00
tsconfig.json Feature/object model refactor (#26) 2018-06-29 16:51:57 -07:00
tslint.json Feature/object model refactor (#26) 2018-06-29 16:51:57 -07:00
webpack.config.js TypeScript conversion (#3) 2018-06-04 14:03:49 -07:00

README.md

Microsoft Azure Cosmos JavaScript SDK

This project provides JavaScript & Node.js SDK library for SQL API of Azure Cosmos Database Service. This project also includes samples, tools, and utilities.

latest npm badge

Useful links:

Installation

Prerequisites

Install Node.js and npm https://docs.npmjs.com/getting-started/installing-node

Node SDK can be consumed in two ways.

Install Core Module Published to NPM

The core module uses the callbacks model for responses, exposed through the DocumentClient

npm install @azure/cosmos

Prerequisites

To use the SDK, first create an account and follow tutorial.

Note:

When connecting to the emulator from the SDK, SSL verification is disabled.

Follow these instructions to run the tests locally.

Tests

Prerequisites

  1. Clone Azure/azure-cosmos-js repository

    git clone https://github.com/azure/azure-cosmos-js.git
    
  2. Install Node.js and npm https://docs.npmjs.com/getting-started/installing-node

  3. Cosmos DB emulator

    • Note: requires a windows machine or ability to run Windows container
  4. Install dependencies

    npm i     # alias for npm install
    
  5. Build the source

    npm run build   # compiles the typescript source, runs linting, creates webpack, creates docs
    

Running the tests

npm run test    # runs all tests

Examples

Hello World

import { CosmosClient } from "@azure/cosmos"

const host = "[hostendpoint]";                     // Add your endpoint
const masterKey = "[database account masterkey]";  // Add the masterkey of the endpoint
const client = new CosmosClient(host, { masterKey });

var databaseDefinition = { id: "sample database" };
var collectionDefinition = { id: "sample collection" };
var documentDefinition = { id: "hello world doc", content: "Hello World!" };

async function helloCosmos() {
    await client.createDatabase(databaseDefinition);
    console.log('created db');

    await client.createCollection(database._self, collectionDefinition);
    console.log('created collection');

    await client.createDocument(collection._self, documentDefinition);
    console.log('Created Document with content: ', document.content);

    await client.deleteDatabase(database._self);
    console.log("Deleted database");
});

helloCosmos().finally(()=>{});

Youtube Videos

Getting started with Node.js SDK:

Azure Demo: Getting started with Document Node.js SDK

Need Help?

Be sure to check out the Microsoft Azure Developer Forums on MSDN or the Developer Forums on Stack Overflow if you have trouble with the provided code.

Contribute Code or Provide Feedback

If you would like to become an active contributor to this project please follow the instructions provided in Azure Projects Contribution Guidelines.

If you encounter any bugs with the library please file an issue in the Issues section of the project.