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

@forgebase/sdk

v0.0.8

Published

A powerful, type-safe TypeScript SDK for interacting with ForgeBase services, providing comprehensive database operations, advanced query capabilities, and type safety.

Readme

ForgeBase TypeScript SDK

A powerful, type-safe TypeScript SDK for interacting with ForgeBase services, providing comprehensive database operations, advanced query capabilities, and type safety.

Core Features

  • Type-Safe Query Builder:

    • Fluent API design
    • Advanced filtering (where, whereIn, whereExists, etc.)
    • Complex joins and relations
    • Aggregations (count, sum, avg, min, max)
    • Window functions (rowNumber, rank, lag, lead)
    • Recursive CTEs
    • Result transformations (pivot, compute)
  • Database Operations:

    • CRUD operations (create, update, delete)
    • Batch operations
    • Pagination (limit, offset)
    • Sorting (orderBy)
  • Security & Validation:

    • Input validation
    • Type inference from your interfaces

Installation

npm install @forgebase/sdk
# or
yarn add @forgebase/sdk
# or
pnpm add @forgebase/sdk

Basic Usage

Initialization

First, define your database schema and initialize the SDK. This provides automatic type safety across your entire application.

import { DatabaseSDK } from '@forgebase/sdk/client';

// 1. Define your entity types
interface User {
  id: number;
  name: string;
  email: string;
  role: 'admin' | 'user';
  status: 'active' | 'inactive';
}

interface Order {
  id: number;
  user_id: number;
  amount: number;
  status: 'pending' | 'completed';
}

// 2. Define your Database Schema
interface Schema {
  users: User;
  orders: Order;
}

// 3. Initialize the SDK with your Schema
const db = new DatabaseSDK<Schema>({
  baseUrl: 'http://localhost:3000',
  axiosConfig: {
    withCredentials: true,
    headers: { 'Content-Type': 'application/json' },
  },
});

Advanced Configuration

Custom Fetch Implementation

You can provide a custom fetch implementation to handle specific environments (like edge functions) or complex authentication requirements.

import { DatabaseSDK } from '@forgebase/sdk/client';
import { authClient } from '@/lib/auth-client'; // Assuming authClient is an instance of Better-auth

const db = new DatabaseSDK<Schema>({
  baseUrl: 'http://localhost:3000',
  // Provide a custom fetch wrapper
  fetch: async (input, init) => {
    const cookies = authClient.getCookie();

    return fetch(input, {
      ...init,
      headers: {
        ...init?.headers,
        Cookie: cookies,
      },
      // Avoid interference with manual cookie headers
      credentials: 'omit',
    });
  },
});

Database Operations

The SDK automatically infers types based on your Schema.

// Query users (Type is inferred as User[])
const users = await db.table('users').select('id', 'name', 'email').where('status', 'active').query();

// Create a new record (Type checking ensures payload matches User)
const newUser = await db.table('users').create({
  name: 'John Doe',
  email: '[email protected]',
  role: 'user',
  status: 'active',
});

// Update a record
await db.table('users').update(1, {
  status: 'inactive',
});

// Delete a record
await db.table('users').delete(1);

Advanced Queries

// Complex filtering
const results = await db
  .table('users') // Type inferred automatically
  .where('status', 'active')
  .andWhere((query) => {
    query.where('role', 'admin').orWhere('email', 'like', '%@company.com');
  })
  .orderBy('name', 'asc')
  .limit(10)
  .query();

// Aggregations
const stats = await db.table('orders').groupBy('status').sum('amount', 'total_amount').count('id', 'order_count').having('total_amount', '>', 5000).query();

// Result type is narrowed:
// stats.data -> { status: string, total_amount: number, order_count: number }[]

// Window Functions
const rankedUsers = await db
  .table('users')
  .select('name', 'department', 'salary')
  .rank('salary_rank', ['department'], [{ field: 'salary', direction: 'desc' }])
  .query();

// Recursive CTEs (e.g., for hierarchical data)
const categories = await db
  .table('categories')
  .withRecursive(
    'category_tree',
    // Initial query
    db.table('categories').where('parent_id', null),
    // Recursive query
    db.table('categories').join('category_tree', 'parent_id', 'id'),
    { unionAll: true },
  )
  .query();

Transformations

You can transform the result set on the client side using pivot or compute.

// Pivot data
const pivoted = await db.table('sales').pivot('month', ['Jan', 'Feb', 'Mar'], { type: 'sum', field: 'amount' }).query();

// Compute new fields
const computed = await db
  .table('employees')
  .compute({
    fullName: (row) => `${row.firstName} ${row.lastName}`,
    tax: (row) => row.salary * 0.2,
  })
  .query();

Error Handling

The SDK throws standard errors that you can catch and handle.

try {
  await db.table('users').create(data);
} catch (error) {
  console.error('Failed to create user:', error.message);
}

Real-time Updates

⚠️ Note: Real-time features (WebSockets/SSE) are currently experimental and under active development. They are not yet fully documented or recommended for production use.

License

MIT