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

@opencharts/query

v0.0.1

Published

Query utilities for OpenCharts

Downloads

169

Readme

@opencharts/query

Canonical query AST, predicate evaluator, capability registry, and value-set registry.

npm License: MIT

Overview

@opencharts/query provides the query layer for canonical resources:

  • CanonicalQuery — typed query object targeting a resource type with an optional where predicate, sort, and limit.
  • PredicateEvaluator — evaluates a query predicate against a resource instance (catalog-driven type dispatch).
  • CanonicalCapabilityContract / CanonicalCapabilityRegistry — declare and look up what operations a source supports.
  • QueryPlanValidator — validates a query against a capability at plan time (before execution).
  • CanonicalValueSetRegistry — named value sets for in / nin membership predicates.

Installation

npm install @opencharts/query

Usage

Build a query

import { CanonicalQuery } from '@opencharts/query';

const query = new CanonicalQuery({
  target: { resource_type: 'Observation' },
  where: {
    op: 'and',
    operands: [
      { op: 'eq',     field: 'code.coding.code', value: '718-7' },
      { op: 'exists', field: 'effective' },
    ],
  },
  sort: [{ field: 'effective', direction: 'desc' }],
  limit: 10,
});

query.validate(); // throws InvalidCanonicalQueryError if malformed

Evaluate a predicate against a resource instance

import { PredicateEvaluator } from '@opencharts/query';

// resources, parameters, valueSets from createCanonicalSystem()
const evaluator = new PredicateEvaluator({ resourceCatalog, parameterCatalog, valueSets });

const matches = evaluator.evaluate(query.where, {
  type: 'Observation',
  parameters: {
    code: { coding: [{ system: 'http://loinc.org', code: '718-7' }] },
    effective: '2024-01-15',
  },
});
// true

Register capabilities

import { CanonicalCapabilityRegistry } from '@opencharts/query';

const capabilities = new CanonicalCapabilityRegistry({ resourceCatalog });

capabilities.register({
  capability: 'observation.search',
  verb: 'search',
  resource_type: 'Observation',
  query: {
    filterable: {
      'code.coding.code': ['eq', 'in'],
      'effective':        ['gt', 'gte', 'lt', 'lte', 'overlaps'],
      'subject_ref':      ['eq'],
    },
    sortable: ['effective'],
    limit: true,
  },
});

Validate a query plan

import { QueryPlanValidator } from '@opencharts/query';

const validator = new QueryPlanValidator({ capabilities });
validator.validate(query, 'observation.search');
// Throws UnsupportedCapabilityQueryError if query uses fields/operators the capability doesn't support

Value sets for in / nin

import { CanonicalValueSetRegistry } from '@opencharts/query';

const valueSets = new CanonicalValueSetRegistry();
valueSets.register('active-statuses', ['active', 'in-progress', 'on-hold']);

// Use in a predicate
const predicate = { op: 'in', field: 'status', valueset: 'active-statuses' };

Query Operators

| Operator | Type | Shape | |---|---|---| | and | logical | { op: 'and', operands: [node, …] } | | or | logical | { op: 'or', operands: [node, …] } | | not | logical | { op: 'not', operand: node } | | exists | presence | { op: 'exists', field } | | eq / neq | comparison | { op, field, value } or { op, field, input } | | gt / gte / lt / lte | comparison | same | | overlaps | period overlap | { op: 'overlaps', field, value } | | in / nin | membership | { op, field, valueset } or { op, field, values: [] } |

Comparisons over collection fields (e.g. identifiers.value) are existential: true if ANY element satisfies.

API Reference

CanonicalQuery

| Member | Description | |---|---| | target | { resource_type, version? } | | where | Predicate AST node (optional) | | sort | [{ field, direction? }] | | limit | Positive integer (optional) | | validate() | Throws on structural errors | | leaves() | Returns [{ field, op }] leaf nodes |

PredicateEvaluator

| Method | Description | |---|---| | evaluate(predicate, resource) | Returns boolean |

CanonicalCapabilityRegistry

| Method | Description | |---|---| | register(contract) | Register a capability contract | | get(capability) | Returns contract; throws if missing | | has(capability) | Returns boolean | | list() | All contracts |

CanonicalValueSetRegistry

| Method | Description | |---|---| | register(id, codes) | Register a named code set | | has(id) | Returns boolean | | includes(id, code) | Returns boolean; throws if set unknown | | codes(id) | Returns string[] |

License

MIT