npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sengi-docstore-cosmosdb

v14.0.0

Published

An Azure CosmosDB document store for Sengi.

Downloads

63

Readme

Sengi DocStore CosmosDB

This package is part of the Sengi family.

npm

A wrapper for Microsoft's Azure Cosmos DB that implements the Sengi document store interface.

Installation

npm install sengi-docstore-cosmosdb

Usage

The CosmosDbDocStore implements the DocStore interface defined in sengi-interfaces.

To instantiate a CosmosDbDocStore you have to provide the following parameters:

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

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

  • getDatabaseNameFunc - A function (docTypeName: string, docTypePluralName: string, options: CosmosDbDocStoreOptions) => string that returns the name of the database to connect to.

  • getContainerNameFunc - A function (databaseName: string, docTypeName: string, docTypePluralName: string, options: CosmosDbDocStoreOptions) => string that returns the name of the container to edit.

  • getPartitionKeyFunc - A function (databaseName: string, containerName: string, docTypeName: string, docTypePluralName: string, id: string, options: CosmosDbDocStoreOptions) => string|null that returns the value of a document's partition key. Typically this will return the id or something from the options object that has been populated by the Sengi interface. For example, the Sengi-Express library will place the additional path components (for example the tenant ID) into the options for use here. If the partition key is not known, just return null and the library will look it up.

const cosmosDbDocStore = new CosmosDbDocStore({
  cosmosUrl: TEST_COSMOS_URL,
  cosmosKey: TEST_COSMOS_KEY,
  getDatabaseNameFunc: (docTypeName: string, docTypePluralName: string, options: CosmosDbDocStoreOptions) => 'sengi',
  getContainerNameFunc: (databaseName: string, docTypeName: string, docTypePluralName: string) => docTypePluralName,
  getPartitionKeyFunc: (databaseName: string, containerName: string, docTypeName: string, docTypePluralName: string, id: string) => docTypePluralName === 'trees' ? id : null
})

Filters

Filters are passed unchanged to the SQL execution engine. For this reason, filters should always be specified server side.

Assume the table is qualified with the letter d. For example, d.myField = 'VALUE' and d.myOtherField > 25.

Setup

To run the tests you will need a locally running instance of Cosmos DB running.

ipaddr="`ifconfig | grep "inet " | grep -Fv 127.0.0.1 | awk '{print $2}' | head -n 1`"
docker pull mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator
docker run -p 8081:8081 -p 10251:10251 -p 10252:10252 -p 10253:10253 -p 10254:10254 --name=cosmos -it mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator

docker run -p 8081:8081 -p 10251:10251 -p 10252:10252 -p 10253:10253 -p 10254:10254  -m 3g --cpus=2.0 --name=test-linux-emulator -e AZURE_COSMOS_EMULATOR_PARTITION_COUNT=10 -e AZURE_COSMOS_EMULATOR_ENABLE_DATA_PERSISTENCE=true -e AZURE_COSMOS_EMULATOR_IP_ADDRESS_OVERRIDE=$ipaddr -it mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator

To run the tests you will need an Azure Account with a Cosmos instance running. If a linux-compatible docker image for Cosmos emerges, this will no longer be necessary.

In the mean-time, you will need to configure the following environent variables:

  • SENGI_COSMOS_URL: https://<your-account-name>.documents.azure.com
  • SENGI_COSMOS_KEY: abcdabcdabcdabcdabcdabcd==

You will then need to run npm run setup in order to create database. This needs to be left running (and available) so that CI/CD tests can run.

You can remove the database by running npm run teardown.

Development

Test run requires the --detectOpenHandles flag because occassionally a handle is held open - no idea why. This slows the opening test by a few seconds. Unable to find any async functions that we're not awaiting on the result, and all network calls are connection-less. Maybe a bug in cosmosclient?

Tests are written using Jest with 100% coverage.

npm test

Note that the tests run sequentially (jest --runInBand) so that only one test can access the database at a time.

Continuous Deployment

Any pushes or pull-requests on non-master branches will trigger the test runner.

Any pushes to master will cause the family of libraries to be re-published.