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 🙏

© 2025 – Pkg Stats / Ryan Hefner

hrana

v0.1.1

Published

A tiny (1034b) runtime-agnostic Hrana HTTP client

Readme

hrana CI licenses

A tiny (1034b) runtime-agnostic Hrana HTTP client

Install

This package is compatible with all JavaScript runtimes and is available on multiple registries:

Usage

import * as hrana from 'hrana';

let credentials: hrana.Config = {
  url: 'https://<database>.turso.io',
  token: 'eyJ...',
};

let rows = await hrana.execute(credentials, {
  sql: 'select * from users where orgid=? limit 2',
  args: [
    hrana.encode('acme'),
  ],
});
//-> {
//->   cols: [
//->     { name: "id", decltype: "INTEGER" },
//->     { name: "name", decltype: "TEXT" },
//->     // ...
//->   ],
//->   rows: [
//->     [
//->       { type: "integer", value: "1" },
//->       { type: "text", value: "lukeed" }
//->       // ...
//->     ],
//->     [
//->       { type: "integer", value: "12" },
//->       { type: "text", value: "foobar" }
//->       // ...
//->     ],
//->   ],
//->   affected_row_count: 0,
//->   last_insert_rowid: null,
//->   replication_index: "...",
//->   rows_read: 2,
//->   rows_written: 0,
//->   query_duration_ms: 0.09,
//-> }

type User = {
  id: number;
  name: string;
  // ...
};

let users = hrana.parse<User>(rows);
//-> [
//->   { id: 1, name: 'lukeed' },
//->   { id: 12, name: 'foobar' },
//-> ]

Transformers

When converting a Hrana.StmtResult into your custom T type, you may provide parse() with column-specific transformers.

For example, to parse an apps.configs (TEXT) column into JSON, you can do this:

type App = {
  id: number;
  name: string;
  config: {
    plan: string;
    seats: number;
  };
};

let apps = hrana.parse<App>(rows, {
  config: (v) => JSON.parse(v as string),
});
//-> [
//->   {
//->     id: 123,
//->     name: 'Example',
//->     config: {
//->       plan: 'Free',
//->       seats: 1,
//->     }
//->   }
//-> ]

Batch Statements

You can execute multiple statements in one roundtrip. These may also be executed conditionally based on the success or failure of previous statements.

See the Hrana 3 Spec for more information.

let r = await hrana.batch(credentials, [{
  stmt: {
    sql: `select 1`,
  },
}, {
  stmt: {
    sql: `select * from users limit 1`,
  },
  condition: {
    type: 'and',
    conds: [{
      type: 'ok',
      step: 0, // only run if Step#0 is ok
    }],
  },
}]);

Transactions

A transaction is like a batch statement except that the group of statements fails/succeeds collectively.

The transaction() helper manages the condition value for each step, and wraps the group with the proper BEGIN, COMMIT, and ROLLBACK statements.

let tx = await hrana.transaction(credentials, 'deferred', {
  sql: 'select * from apps limit 1',
}, {
  sql: 'select * from apps limit 1 offset 2',
});

console.log(
  tx.step_results.forEach((r) =>
    r && m.parse<App>(r, {
      config: (v) => JSON.parse(v as string),
    })
  ),
);

API

Please refer to the generated API documentation, as it's always kept up-to-date.

Note: The API is the same across all JavaScript runtimes, regardless of registry — only the package name changes.

License

MIT © Luke Edwards