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

@typed-clickhouse/core

v0.2.0

Published

Type-safe, code-first ClickHouse schema, migrations and query layer for TypeScript. Declare tables and views as types (OlapTable, View, MaterializedView) and a compiler plugin derives the ClickHouse schema at build time. No native dependencies, so it also

Readme

@typed-clickhouse/core

npm MIT license

The TypeScript library for typed-clickhouse, a type-driven, ClickHouse-only schema and query toolkit. You declare ClickHouse tables and views as TypeScript types; a compiler plugin derives their schema from those types at build time; the typed-clickhouse CLI diffs that schema against a live database, generates a migration plan, and applies it. This package also provides a typed SQL query layer for reading and writing that data.

It has no native (C++/Rust) dependencies, so it works in AWS Lambda, Edge runtimes, and other environments where native addons can't be compiled or loaded.

Installation

npm install @typed-clickhouse/core

If you use OlapTable<T>, MaterializedView<T>, or other generic resources that require compile-time schema injection, you also need the compiler plugin's peer dependencies:

npm install -D ts-patch typia typescript

Compiler Plugin Setup

The library's compiler plugin transforms generic resource declarations like new OlapTable<MyType>(...) at compile time, injecting JSON schemas, column definitions, and runtime validators. Without it, you'll get:

Supply the type param T so that the schema is inserted by the compiler plugin.

1. Configure tsconfig.json

Add the compiler plugin and typia transform to your tsconfig.json:

{
  "compilerOptions": {
    "plugins": [
      {
        "transform": "@typed-clickhouse/core/compilerPlugin"
      },
      {
        "transform": "typia/lib/transform"
      }
    ]
  }
}

Both @typed-clickhouse/core/compilerPlugin and @typed-clickhouse/core/dist/compilerPlugin.js work — use whichever you prefer.

2. Install ts-patch

npx ts-patch install

3. Build with tspc instead of tsc

npx tspc

Or add it to your package.json scripts:

{
  "scripts": {
    "build": "tspc"
  }
}

Note: tspc is a drop-in replacement for tsc that loads the compiler plugins defined in tsconfig.json. Standard tsc ignores the plugins array.

Usage

import { OlapTable, sql } from "@typed-clickhouse/core";

interface Event {
  id: string;
  createdAt: Date;
  label: string;
}

// Compiler plugin injects the schema from the `Event` type param at build time.
const events = new OlapTable<Event>("events", {
  orderByFields: ["id", "createdAt"],
});

await events.insert([{ id: "1", createdAt: new Date(), label: "signup" }]);

const recent = sql`SELECT * FROM ${events} ORDER BY createdAt DESC LIMIT 10`;

Both CommonJS (require) and ES Modules (import) builds are published — use whichever your runtime targets.

ClickHouse Configuration for Serverless

In a standard project, ClickHouse connection details are read from tch.config.toml. This file doesn't exist in serverless environments, so calling OlapTable.insert() would throw a ConfigError.

Use configureClickHouse() to provide connection details programmatically. Call it once during cold start, before any .insert() calls:

import { configureClickHouse, OlapTable } from "@typed-clickhouse/core";

// Call once at module level (runs during Lambda cold start)
configureClickHouse({
  host: process.env.CLICKHOUSE_HOST!,
  port: process.env.CLICKHOUSE_PORT!,       // string, e.g. "8443"
  username: process.env.CLICKHOUSE_USER!,
  password: process.env.CLICKHOUSE_PASSWORD!,
  database: process.env.CLICKHOUSE_DATABASE, // optional — only if your OlapTable configs don't specify `database`
  useSSL: true,
});

// Define your table (compiler plugin injects schema at build time)
const myTable = new OlapTable<MyType>("my_table");

export async function handler(event: any) {
  const data = parseEvent(event);
  await myTable.insert([data]);  // Works without tch.config.toml
  return { statusCode: 200 };
}

ClickHouseConfig fields

| Field | Type | Example | | --- | --- | --- | | host | string | "clickhouse.example.com" | | port | string | "8443" | | username | string | "default" | | password | string | "secret" | | database | string? | "my_database" (optional — only needed if your OlapTable configs don't specify database) | | useSSL | boolean | true |

What's Included

| Export | Description | | --- | --- | | OlapTable | Define ClickHouse OLAP tables | | View, MaterializedView | Define views and materialized views | | SqlResource | Define arbitrary raw-SQL-backed resources | | sql, Sql | Tagged template literal (and its AST type) for building SQL queries | | select, where, join, groupBy, having, orderBy, limit, offset, paginate | Query-builder helpers on top of the SQL layer | | and, or, not, eq, ne, gt, gte, lt, lte, like, ilike, inList, notIn, isNull, isNotNull, between | Filter/condition builders | | count, countDistinct, sum, avg, min, max | Aggregation helpers | | defineQueryModel, QueryClient, createQueryHandler, registerModelTools | Typed query-model layer, including MCP tool generation | | SelectRowPolicy, buildRowPolicyOptionsFromClaims, MOOSE_RLS_ROLE, MOOSE_RLS_USER, MOOSE_RLS_SETTING_PREFIX | Row-level security policies | | LifeCycle, ClickHouseEngines | Table lifecycle and ClickHouse engine constants | | DataSource | Base class for external data source connectors | | WebApp | Mount a generic HTTP handler alongside your ClickHouse resources | | configureClickHouse | Provide ClickHouse connection config programmatically (no tch.config.toml) — see above | | getClickhouseClient | Get the underlying ClickHouse client | | parseCSV, parseJSON, parseJSONWithDates | Data parsing utilities | | mooseEnvSecrets, mooseRuntimeEnv | Secrets and runtime environment helpers | | Registry functions | getTables, getTable, getViews, getView, getMaterializedViews, getMaterializedView, getSqlResources, getSqlResource, getWebApps, getWebApp, getSelectRowPolicies, getSelectRowPolicy | | Utility functions | cliLog, compilerLog, mapTstoJs, getFileName, logError, quoteIdentifier |

This is a representative subset. See tests/golden/exports.json for the exact, generated list of every runtime export.

No Native Dependencies

This package — and the internal workspace library it bundles — has no native (C++/Rust) dependencies. There is no streaming layer, no workflow orchestrator, and no message-broker or job-scheduler client anywhere in this project; it ships ClickHouse tooling only. That means there is nothing here that can fail to compile or load in Lambda, Edge, or other restricted runtimes.

typed-clickhouse CLI Compatibility

This package ships the tch-tspc and tch-runner binaries that the typed-clickhouse CLI uses to compile and run your TypeScript models.

The CLI itself lives in apps/cli of this same repository. Install it separately (build it from source, or use whatever distribution channel your project relies on), then use it as normal:

CI/CD Usage

# GitHub Actions example
steps:
  - run: npm install
  - run: typed-clickhouse generate migration
  - run: typed-clickhouse migrate

The tch-tspc and tch-runner binaries are automatically available in node_modules/.bin/ after npm install — the typed-clickhouse CLI will find them there.

No extra configuration is needed beyond the standard Compiler Plugin Setup above.

Origin

This package is derived from 514-labs/moosestack, MIT licensed, Copyright (c) 2023 Tim Delisle, Nicolas Joseph. See NOTICE for the full attribution.

  • Original project: https://github.com/514-labs/moosestack

License

MIT — see LICENSE for details.