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

@lightdash/query-sdk

v0.2662.2

Published

SDK for building custom data apps against the Lightdash semantic layer

Readme

@lightdash/query-sdk

A React SDK for building custom data apps against the Lightdash semantic layer.

Quick start

import {
    createClient,
    LightdashProvider,
    useLightdash,
} from '@lightdash/query-sdk';

const lightdash = createClient();

function App() {
    return (
        <LightdashProvider client={lightdash}>
            <Dashboard />
        </LightdashProvider>
    );
}

function Dashboard() {
    const { data, loading, error } = useLightdash(
        lightdash
            .model('orders')
            .dimensions(['customer_segment'])
            .metrics(['total_revenue', 'order_count'])
            .filters([
                {
                    field: 'order_date',
                    operator: 'inThePast',
                    value: 90,
                    unit: 'days',
                },
            ])
            .sorts([{ field: 'total_revenue', direction: 'desc' }])
            .limit(10),
    );

    if (loading) return <p>Loading...</p>;
    if (error) return <p>Error: {error.message}</p>;

    return (
        <ul>
            {data.map((row, i) => (
                <li key={i}>
                    {row.customer_segment}: {row.total_revenue}
                </li>
            ))}
        </ul>
    );
}

Result rows are flat objects with raw typed values (numbers are numbers, strings are strings).

Authentication

The SDK reads credentials from env vars. For Vite projects, add a .env file:

VITE_LIGHTDASH_API_KEY=your-pat-token
VITE_LIGHTDASH_URL=https://app.lightdash.cloud
VITE_LIGHTDASH_PROJECT_UUID=your-project-uuid

For Node/E2B environments, use unprefixed names (LIGHTDASH_API_KEY, etc.).

Calling createClient() with no arguments reads from env vars. You can also pass config explicitly:

const lightdash = createClient({
    apiKey: token,
    baseUrl: 'https://app.lightdash.cloud',
    projectUuid: 'uuid',
});

Query builder

Queries are built with a chainable, immutable API. Fields use short names (e.g. driver_name), and the SDK qualifies them automatically for the API.

lightdash
    .model('orders')
    .dimensions(['customer_name', 'order_date'])
    .metrics(['total_revenue', 'order_count'])
    .filters([
        { field: 'status', operator: 'equals', value: 'completed' },
        { field: 'amount', operator: 'greaterThan', value: 1000 },
        { field: 'order_date', operator: 'inThePast', value: 90, unit: 'days' },
    ])
    .sorts([{ field: 'total_revenue', direction: 'desc' }])
    .limit(100);

Supported filter operators: equals, notEquals, greaterThan, lessThan, greaterThanOrEqual, lessThanOrEqual, inThePast, notInThePast, inTheNext, inTheCurrent, notInTheCurrent, inBetween, notInBetween, isNull, notNull, startsWith, endsWith, include, doesNotInclude.

Results

useLightdash(query) returns:

| Field | Type | Description | | --------- | --------------- | ---------------------------------------------------------------- | | data | Row[] | Array of flat objects. Numbers are numbers, strings are strings. | | loading | boolean | True while the query is running. | | error | Error \| null | Error if the query failed. | | refetch | () => void | Re-run the query. |

User context

const user = await lightdash.auth.getUser();
// { name: 'John Doe', email: '...', role: 'admin', orgId: '...', attributes: {} }

How it works

  1. createClient() sets up auth and the API transport
  2. <LightdashProvider> makes the transport available to hooks via React context
  3. useLightdash(query) posts to the async metric query endpoint, polls for results, and returns flat rows
  4. Field IDs are auto-qualified (driver_name becomes fct_race_results_driver_name for the API)

Development

pnpm -F query-sdk typecheck    # type check
pnpm -F query-sdk lint          # lint
pnpm -F query-sdk fix-format    # format with oxfmt

See example/ for a working F1 dashboard demo.