0.2.5 • Published 4 years ago

jsonotron-cosmosdb v0.2.5

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

A wrapper that allows Cosmos DB to be used as a document store for Jsonotron

npm.io npm JavaScript Style Guide

A wrapper for Azure Cosmos DB that implements the Jsonotron document store interface.

This package is part of the Jsonotron system.

Jsonotron is...

  • a small set of components for building a NodeJS microservice
  • for storing, patching and querying JSON documents
  • stored in a schemaless/NoSQL database
  • that have known, enforceable, and evolving schemas.

Visit https://karlhulme.github.io/jsonotron/ for details on how to get started.

Installation

npm install jsonotron-cosmosdb --save

Usage

To instantiate a CosmosDbDocStore you have to provide 3 parameters:

  • cosmosUrl - A url that identifies your Cosmos DB instance.

  • cosmosKey - A master key with read and write access to your Cosmos DB instance.

  • config - A configuration object

    • getDatabaseName - A function (docTypeName, docTypePluralName, options) that returns the name of the database to connect to.

    • getContainerName - A function getContainerName (databaseName, docTypeName, docTypePluralName, options) that returns the name of the container to edit.

    • getPartitionKey - A function (databaseName, containerName, docTypeName, docTypePluralName, id, options) that returns the value of the containers partition key. Typically this will return the id or something from the options object that has been populated by the Jsonotron interface. For example, the Jsonotron-Express library will place the additional path components (for example the tenant ID) into the options for use here.

const { createCosmosDbDocStore } = require('jsonotron-cosmosdb')

const cosmosDbDocStore = createCosmosDbDocStore({
  cosmosUrl: 'https://documents.azure...',
  cosmosKey: 'ABCD_KEY_FROM_AZURE_PORTAL',
  config: {
    getDatabaseName: (docTypeName, docTypePluralName, options) => 'myDatabase',
    getContainerName: (databaseName, docTypeName, docTypePluralName, options) => 'myContainer',
    getPartitionKey: (databaseName, containerName, docTypeName, docTypePluralName, id, options) => id
  }
)

cosmosDbDocStore.upsert('test', 'tests', {
  id: '0001',
  docType: 'test',
  docOps: [],
  hello: 'world'
})

Development

Code base adheres to the rules chosen by https://standardjs.com/. Code is formatted with 2 spaces.

Tests are written using Jest with 100% coverage.

To run the tests locally you will need an Azure Cosmos Account with a database named jsonotron and 2 containers named shows and mixed.

You will also need to set the following environment variables on your local machine:

  • JSONOTRON_COSMOS_URL: https://<your-account-name>.documents.azure.com
  • JSONOTRON_COSMOS_KEY: abcdabcdabcdabcdabcdabcd==
npm test

Continuous Deployment

Any commits to master will cause the library to be re-published.

0.2.5

4 years ago

0.2.4

4 years ago

0.2.1

4 years ago

0.2.2

4 years ago

0.1.0

4 years ago

0.2.0

4 years ago

0.0.1

4 years ago