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

@sawala/datana-client

v0.2.0

Published

TypeScript client for the Datana public read API — Sawala Cloud's structured-data platform. Framework-agnostic, runs in Node, browsers, and Cloudflare Workers.

Downloads

304

Readme

@sawala/datana-client

TypeScript client for the public read API of Datana — Sawala Cloud's structured-data platform. Framework-agnostic; runs in Node, browsers, and Cloudflare Workers.

Install

npm install @sawala/datana-client

Requires Node 18+ (for the built-in fetch).

Quickstart

import { createDatanaClient } from '@sawala/datana-client'

const datana = createDatanaClient({
  projectId: 'proj_acme123',
  publicApiKey: 'pk_live_xxx', // a publishable key from your Datana project's API keys
})

interface Startup {
  title: string
  slug: string
  city: string
  industry_sector: string[]
}

const { items, pagination } = await datana.listRecords<Startup>('startup', { limit: 20 })
console.log(items[0]?.data.title, pagination.hasMore)

Only published records of public collections are returned, and any fields a collection marks private are stripped server-side — this client cannot see them.

API

getCollection(slug)

Fetch a collection's schema (its fields, types, and select/relation options) — useful for building filter dropdowns or generating types. Private fields are not included. Returns null if the collection is missing or not public.

const col = await datana.getCollection('startup')
col?.fields.forEach((f) => console.log(f.name, f.type, f.options?.enum))

listRecords<T>(slug, params?)

List published records with server-side filtering, search, sorting, and cursor pagination.

const { items, pagination } = await datana.listRecords<Startup>('startup', {
  filter: { industry_sector: 'fintech', city: 'palembang' }, // array fields match by membership
  q: 'bot',          // case-insensitive title search
  sort: '-createdAt',
  limit: 25,
})

filter accepts an object ({ field: value } → one field:value each) or raw strings for advanced ops:

await datana.listRecords('startup', { filter: ['total_employees:gte:10', 'industry_sector:in:fintech,edu'] })

Page through everything with the cursor:

let cursor: string | undefined
do {
  const page = await datana.listRecords<Startup>('startup', { limit: 100, cursor })
  for (const r of page.items) handle(r)
  cursor = page.pagination.nextCursor ?? undefined
} while (cursor)

getRecord<T>(slug, id)

Fetch one published record by id; null if missing or not published.

const startup = await datana.getRecord<Startup>('startup', '01J…')

aggregate(slug, params)

Counts over published records — for stat cards, region/sector/SDG breakdowns, and facet counts. Works on single and array fields.

await datana.aggregate('startup', { count: true })                 // { total: 501 }
await datana.aggregate('startup', { groupBy: 'province' })         // { groups: { 'dki-jakarta': 119, … } }
await datana.aggregate('startup', { groupBy: 'industry_sector' })  // array field, unnested
await datana.aggregate('startup', { distinct: ['city', 'industry_sector'] })

Options

| Option | Required | Description | |--------|----------|-------------| | projectId | yes | Your Datana project id (proj_…). | | publicApiKey | yes | A publishable key (pk_live_…/pk_test_…). Browser-safe; never use a secret (sk_…) key in client code. | | baseUrl | no | Defaults to https://api.sawala.cloud/public/datana. | | fetchImpl | no | Override the global fetch. |

Scope

This is a public read client. Creating, updating, or publishing records is done through the authenticated dashboard / CLI, not this SDK.

License

MIT