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

@fathom-sql/sql

v1.0.5

Published

Fathom SQL Parser SDK — MoonBit-built parse/format/complete/lint/fingerprint/lineage for Doris and Flink SQL

Readme

@fathom-sql/sql

npm version CI License MoonBit Targets Doris Flink

Part of Fathom SQL Parser SDK — see the root README for the full feature list, architecture, and release notes.

A MoonBit-built parser and toolchain for Apache Doris and Apache Flink SQL, exposed as a self-contained ES module. The package ships the built JavaScript binding (binding.js), the linear-Wasm artifact (binding.wasm), TypeScript declarations, and dialect/profile capability metadata — no native dependencies, no network calls, no database connection.

Features

  • Dual-dialect parsing — Doris (2.1 / 3.x / 4.x) and Flink (flink-2.3.0 / flink-2.1.3 / flink-1.20.5) with version-aware keyword classification and feature gating.
  • Lossless syntax tree — Parse results preserve byte ranges for every token, comment, whitespace, and error node; the tree round-trips back to the original source.
  • Structured diagnostics — Stable FATHOM-PARSE-* codes with severity, byte ranges, and statement IDs; never crashes on incomplete or malformed input.
  • Editor modestrict for validation, editor for error-recovery on half-typed SQL (IDE scenario).
  • CST formatting — Keyword case, indentation, line width, comma style, newline style, trailing-newline policy; refuses to emit partial output on error trees.
  • SQL fingerprinting — Deterministic content-normalized fingerprint for query caching and deduplication.
  • Column-level lineage — Trace input/output columns from DML/DDL through a caller-injected Catalog (Doris only).

Install

npm install @fathom-sql/sql

Quick start (Node)

import { parse, format, fingerprint, capabilities } from '@fathom-sql/sql';

// Parse — validate SQL and get structured diagnostics
const result = parse('SELECT 1', 'doris', '4.x', 'strict');
console.log(result.valid);          // true
console.log(result.diagnostics);    // []

// Format — canonical output preserving comments
const fmt = format('select 1', 'doris', '4.x', 'strict', { keyword_case: 'upper' });
console.log(new TextDecoder().decode(new Uint8Array(fmt.formatted)));  // "SELECT 1\n"

// Fingerprint — deterministic content hash
const fp = fingerprint('SELECT 1', 'doris', '4.x', 'strict');
console.log(fp.fingerprint);        // non-empty deterministic string

// Capabilities — discover supported dialects and profiles
console.log(capabilities());
// { dialects: [ { dialect: 'doris', profiles: [...] }, { dialect: 'flink', profiles: [...] } ] }

// Diagnostics carry byte offsets — convert to line/column for editor display
import { byteOffsetToLineColumn, withLineColumns } from '@fathom-sql/sql';

const result2 = parse('SELECT FROM', 'doris', '4.x', 'strict');
const pos = byteOffsetToLineColumn('SELECT FROM', result2.diagnostics[0].start_byte);
// { line: 0, column: 7 }

withLineColumns('SELECT FROM', result2.diagnostics); // adds start_line/column in-place

Browser usage

The same ESM entry works in bundlers (Vite/webpack/Rollup) and modern browsers. The binding is self-contained — no Node built-ins, no fs, no path.

<script type="module">
  import { parse } from 'https://esm.sh/@fathom-sql/[email protected]';

  const result = parse('SELECT * FROM t', 'doris', '4.x', 'strict');
  console.log(result.valid);
</script>

API reference

All functions accept string or Uint8Array as the raw input and return decoded JSON envelopes (the fathom.*.v1 wire schema). See index.d.ts for full TypeScript signatures.

| Function | Wire schema | Description | |---|---|---| | parse(raw, dialect, profile, mode?) | fathom.parse.v1 | Parse SQL; returns valid, diagnostics[], CST metadata | | format(raw, dialect, profile, mode?, options?) | fathom.format.v1 | Format SQL; returns accepted, formatted (byte array), diagnostics[] | | complete(raw, dialect, profile, cursorByte) | fathom.complete.v1 | Syntax-aware completion at cursor position | | lint(raw, dialect, profile, mode?) | fathom.lint.v1 | Lint SQL; returns diagnostics with lint-specific codes | | fingerprint(raw, dialect, profile, mode?) | fathom.fingerprint.v1 | Deterministic content-normalized fingerprint | | capabilities() | fathom.capabilities.v1 | Supported dialects and profiles metadata | | dialect(d) | fathom.dialect.v1 | Per-dialect profile and feature metadata | | byteOffsetToLineColumn(raw, byteOffset) | — (JS helper) | Convert UTF-8 byte offset to 0-based { line, column } | | lineColumnToByteOffset(raw, line, column) | — (JS helper) | Convert 0-based { line, column } to UTF-8 byte offset | | withLineColumns(raw, diagnostics) | — (JS helper) | Attach start_line/start_column/end_line/end_column to diagnostics in-place |

Types

type Dialect = 'doris' | 'flink';
type DorisProfile = '2.1' | '3.x' | '4.x';
type FlinkProfile = 'flink-2.3.0' | 'flink-2.1.3' | 'flink-1.20.5';
type Profile = DorisProfile | FlinkProfile;
type Mode = 'strict' | 'editor';
type Raw = string | Uint8Array;

interface FormatOptions {
  keyword_case?: 'upper' | 'lower';
  indent?: number;          // default 2
  line_width?: number;      // default 100
  comma_style?: 'trailing' | 'leading';
  newline_style?: 'follow' | 'lf' | 'crlf';
  trailing_newline?: boolean;
}

Boundaries

  • Flink support is syntax-level only: lexical and grammar coverage, diagnostics, and formatting — no planner, catalog resolution, type checking, or execution equivalence for the Flink engine.
  • Wasm GC is not a first-class target: only linear Wasm and the JS backend are published.
  • Lineage is Doris-only: lineage() rejects a Flink selection with a structured FATHOM-SCHEMA-* error.

See the full release notes and boundary disclosure in the GitHub repository.

Building from source

git clone https://github.com/tchivs/fathom-sql.git
cd fathom-sql
node npm/build.mjs   # builds js+wasm binding, copies artifacts,
                     # regenerates capabilities.json, packs the tarball

Requires the MoonBit toolchain (pinned to moon 0.1.20260819 via .github/moonbit-toolchain.json).

Links

License

Apache-2.0 — see LICENSE.