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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@atomiqlabs/storage-cosmosdb

v1.0.0

Published

Microsoft Azure CosmosDB storage implementation for atomiqlabs SDK

Readme

@atomiqlabs/storage-cosmosdb

@atomiqlabs/storage-cosmosdb is the Azure Cosmos DB-backed storage adapter for the Atomiq SDK in Node.js backend environments. The SDK uses browser IndexedDB by default. Backends, workers, and shared services need to provide storage implementations explicitly. This package provides those implementations on top of Azure Cosmos DB for NoSQL containers.

What this package provides

  • CosmosDBSwapStorage: persistent unified swap storage used by the SDK for swap records and indexed queries.
  • CosmosDBSwapPatchStorage: persistent unified swap storage that writes Cosmos DB patch operations for existing swap records when possible.
  • CosmosDBStorageManager: persistent storage manager used for chain-specific SDK stores.
  • CosmosDBConcurrencyError: error thrown when a Cosmos DB ETag-based concurrency check fails.

Each storage instance uses one Cosmos DB container. Constructors take the container id, the Cosmos DB connection string, and an optional database name. The database name defaults to Atomiq.

When to use it

Use this package when you run the Atomiq SDK in:

  • Node.js backend services
  • backend workers
  • Azure-specific runtimes such as Azure Functions or other serverless function apps
  • server-side deployments that need shared cloud persistence
  • environments where local SQLite files are not suitable

Do not use this package from browser or React Native apps, because the Cosmos DB connection string must stay server-side. Browser apps usually use the SDK's default IndexedDB storage, and React Native apps can use @atomiqlabs/storage-rn-async.

Installation

npm install @atomiqlabs/sdk @atomiqlabs/base @atomiqlabs/storage-cosmosdb

This adapter uses @azure/cosmos under the hood. Your application needs access to an Azure Cosmos DB for NoSQL account and a connection string for that account.

Cosmos DB setup

During SDK initialization, the adapter creates the configured database and containers if they do not already exist.

  • Swap storage containers use partition key /id and an indexing policy generated from the SDK's simple and composite swap indexes.
  • Chain storage manager containers use partition key /id with indexing disabled.
  • If you pre-create containers, configure them with the same partition key and compatible indexing policy.
  • Use stable container ids for each swap chain and chain-specific store. Changing a container id points the SDK at a different storage namespace.

SDK Usage

Pass CosmosDBSwapStorage as swapStorage and CosmosDBStorageManager as chainStorageCtor when creating the swapper.

import {BitcoinNetwork, SwapperFactory, TypedSwapper} from "@atomiqlabs/sdk";
import {CosmosDBStorageManager, CosmosDBSwapStorage} from "@atomiqlabs/storage-cosmosdb";

const connectionString = process.env.ATOMIQ_COSMOSDB_CONNECTION_STRING;
if(connectionString == null) throw new Error("Missing ATOMIQ_COSMOSDB_CONNECTION_STRING");

const chains = [SolanaInitializer, StarknetInitializer, CitreaInitializer] as const;
type SupportedChains = typeof chains;

const Factory = new SwapperFactory<SupportedChains>(chains);

const swapper: TypedSwapper<SupportedChains> = Factory.newSwapper({
    chains: {
        ...
    },
    bitcoinNetwork: BitcoinNetwork.MAINNET,
    // In Node.js, provide persistent storage because the SDK's default
    // browser storage implementation is IndexedDB.
    swapStorage: chainId => new CosmosDBSwapStorage(
        `ATQ_SWAPS_${chainId}`,
        connectionString
    ),
    chainStorageCtor: name => new CosmosDBStorageManager(
        `ATQ_STORE_${name}`,
        connectionString
    )
});

await swapper.init();

To use a custom database name, pass it as the third constructor argument:

swapStorage: chainId => new CosmosDBSwapStorage(
    `ATQ_SWAPS_${chainId}`,
    connectionString,
    "MyAtomiqDatabase"
)

Patch-based swap storage

CosmosDBSwapPatchStorage has the same constructor shape as CosmosDBSwapStorage, plus an optional fourth optimisticConcurrency argument.

import {CosmosDBSwapPatchStorage} from "@atomiqlabs/storage-cosmosdb";

swapStorage: chainId => new CosmosDBSwapPatchStorage(
    `ATQ_SWAPS_${chainId}`,
    connectionString,
    "Atomiq",
    true
)

Use CosmosDBSwapPatchStorage when you want existing swap updates to be sent as Cosmos DB patch operations where possible. When optimisticConcurrency is true, patch, replace, and delete operations for previously loaded swaps include the loaded ETag and throw CosmosDBConcurrencyError if the document changed concurrently. The default is false.

Notes

  • CosmosDBSwapStorage stores one swap per Cosmos DB item and uses Cosmos DB indexes generated from the SDK-provided storage schema.
  • Swap containers and chain storage containers are separate. Use distinct, stable container ids for swapStorage and chainStorageCtor.
  • CosmosDBConcurrencyError includes the affected itemIds so callers can decide whether to retry, reload, or surface the conflict.
  • Persistence, availability, throughput, and backup behavior depend on the Azure Cosmos DB account configuration you choose.