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

@congruent-stack/congruent-api-cli

v0.18.0

Published

Typescript schema-first tooling for agnostic REST APIs.

Readme

@congruent-stack/congruent-api-cli

CLI for congruent-api: scaffolds a handler folder tree from an API contract.

Given a contract module, it generates one folder per path segment for every endpoint, an HTTP-method subfolder (GET, POST, ...) under each, and a handler.ts stub inside.

Usage

congruent-api <contract-path> <out-dir> [endpoint-path] [--force]

Without installing:

pnpm dlx @congruent-stack/congruent-api-cli ./src/contract.ts ./src/handlers
# or: npx @congruent-stack/congruent-api-cli ./src/contract.ts ./src/handlers

⚡ Use it from package.json scripts

Install it as a devDependency:

pnpm add -D @congruent-stack/congruent-api-cli

then wire the congruent-api bin into your scripts:

{
  "scripts": {
    // generate handler stubs for every endpoint in the contract
    "gen:handlers": "congruent-api ./src/contract.ts ./src/handlers",

    // regenerate everything from scratch (overwrites existing handler.ts files!)
    "gen:handlers:force": "congruent-api ./src/contract.ts ./src/handlers --force"
  }
}
pnpm gen:handlers

# scaffold just one new endpoint:
pnpm gen:handlers -- /somepath/:myparam

Extra arguments after -- are appended to the script, so pnpm gen:handlers -- /somepath/:myparam scaffolds only that endpoint. Re-running is always safe by default — existing handler.ts files are skipped, only newly added endpoints get scaffolded.

Arguments

| Argument | Description | | --- | --- | | contract-path | Path to the module exporting the api contract (.ts or .js). TypeScript is loaded directly via tsx — no build step needed. The first ApiContract-like export is used (contract and default take precedence). | | out-dir | Directory the folder tree is generated into (created if missing). | | endpoint-path | Optional full generic endpoint path (e.g. /somepath/:myparam, leading slash optional). When given, folders are generated only for that endpoint. An unknown path fails and lists the contract's endpoint paths. |

Options

| Option | Description | | --- | --- | | --force | Overwrite existing handler.ts files. By default existing files are skipped, so re-running after adding endpoints never clobbers implemented handlers. |

Example

For this contract:

import { apiContract, endpoint } from '@congruent-stack/congruent-api';

export const contract = apiContract({
  somepath: {
    [':myparam']: {
      POST: endpoint({ /* ... */ }),
    },
  },
  otherpath: {
    GET: endpoint({ /* ... */ }),
    POST: endpoint({ /* ... */ }),
  },
});

running

congruent-api ./src/contract.ts ./src/handlers

generates:

handlers/
├── somepath/
│   └── +myparam/           ← ':myparam' path parameter
│       └── POST/
│           └── handler.ts
└── otherpath/
    ├── GET/
    │   └── handler.ts
    └── POST/
        └── handler.ts

Path parameter segments (:myparam) become +myparam folders — : is not a valid character in Windows folder names.

Each handler.ts contains a registration stub with the method and generic path filled in:

route(apiReg, 'POST /somepath/:myparam')
  .inject(scope => ({

  }))
  .register(async (_req) => {
    throw Error('Not implemented')
  });

Programmatic API

The same functionality is exported from the package:

import { loadContractDefinition, generateEndpointFolders } from '@congruent-stack/congruent-api-cli';

const definition = await loadContractDefinition('./src/contract.ts');
const { createdDirs, createdFiles, skippedFiles } = await generateEndpointFolders({
  definition,
  outDir: './src/handlers',
  endpointPath: '/somepath/:myparam', // optional
  force: false,                       // optional
});

Also exported: collectEndpointPaths(definition) (walks a contract definition and returns every endpoint path with its methods), segmentToFolderName(segment), endpointPathToSegments(path), and renderHandler(method, genericPath).