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

@shellicar/cosmos-query-builder

v1.1.2

Published

A type-safe query builder for Azure Cosmos DB for NoSQL

Downloads

138

Readme

@shellicar/cosmos-query-builder

A type-safe query builder for Azure Cosmos DB for NoSQL

npm package build status

Note: This library is for Azure Cosmos DB for NoSQL (formerly SQL API). For MongoDB API, see Azure Cosmos DB for MongoDB.

Features

  • 🎯 Type-safe field access - IntelliSense and compile-time validation instead of error-prone string queries
  • Builder pattern - Use methods instead of writing raw SQL strings
  • 🔍 Type-safe advanced operators - Array operations like ARRAY_CONTAINS and Cosmos DB functions with full type safety
  • Type-safe patch operations - JSON patch document creation with compile-time path validation
  • Automatic parameter generation - Dynamic @p0, @p1 parameter binding without manual parameter management
  • 🚀 Built-in execution - Execute queries directly with pagination and total count support

Installation & Quick Start

npm i --save @shellicar/cosmos-query-builder
pnpm add @shellicar/cosmos-query-builder
import { createCosmosQueryBuilder, SortDirection } from '@shellicar/cosmos-query-builder';

const builder = createCosmosQueryBuilder<Person>();

builder.where('type', 'eq', 'Person');
builder.where('age', 'gt', 18);
builder.orderBy('created', SortDirection.Desc);
builder.limit(50);

const results = await builder.getAll(container);

For a complete working example, see examples/simple/src/main.ts.

@shellicar TypeScript Ecosystem

Core Libraries

Reference Architectures

Build Tools

Framework Adapters

Logging & Monitoring

Motivation

I wanted a type-safe interface for Azure Cosmos DB for NoSQL and couldn't find any existing solutions for TypeScript.

Originally developed for the Circuit Breaker platform at Hope Ventures, this library was graciously allowed to be released as open source.

Feature Examples

Type-safe query builder for Azure Cosmos DB, supporting advanced operators and structured filtering.

See readme examples for example source code.

  • Builder pattern - Use methods like where(), orderBy(), limit() instead of writing raw SQL.
builder.where('type', 'eq', 'Person');
builder.where('age', 'gt', 18);
builder.orderBy('created', SortDirection.Desc);
builder.limit(50);
  • Advanced operators - Array operations like contains, in, and fuzzy search across multiple fields.
builder.where('bones', 'contains', 'arm');
builder.where('name.givenName', 'in', ['John', 'Jane']);
builder.whereFuzzy('steve', ['name.givenName', 'name.familyName', 'email']);
  • Type-safe field access - IntelliSense and compile-time validation for field paths and values.
// @ts-expect-error: Argument of type 'number' is not assignable to parameter of type 'string'.
builder.where('age', 'eq', 'invalid');
builder.where('age', 'eq', 25);
  • Structured filtering - Use filter objects with type information for complex queries.
type PersonFilter = {
  name?: {
    givenName?: StringFilter;
  };
};
const filter = {
  name: {
    givenName: { __typeInfo: 'StringFilter', eq: 'John' }
  }
} satisfies PersonFilter;
builder.buildQuery(filter);
  • Patch operations - Create type-safe JSON patch documents for Cosmos DB.
const operations = builder.patch({
  op: 'replace',
  path: '/name/givenName',
  value: 'Smith'
});
await container.item('id', 'partitionKey').patch(operations);

Usage

Check the test files for different usage scenarios.

import { createCosmosQueryBuilder, SortDirection } from '@shellicar/cosmos-query-builder';
import type { Container } from '@azure/cosmos';

type Person = {
  id: string;
  type: 'Person';
  age: number;
  created: string;
  name: {
    givenName: string;
    familyName: string;
  };
};

const queryPeople = async (container: Container) => {
  const builder = createCosmosQueryBuilder<Person>();
  
  builder.where('type', 'eq', 'Person');
  builder.where('age', 'gt', 18);
  builder.orderBy('created', SortDirection.Desc);
  builder.limit(50);
  
  const results = await builder.getAll(container);
  console.log(`Found ${results.count} people`);
  
  return results.items;
};

Credits & Inspiration

Originally developed for Circuit Breaker platform.

Special thanks to Hope Ventures for graciously allowing this code to be open sourced.