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

inflow-materialize

v0.3.0

Published

Type-safe materialized views for Inflow Inventory with Drizzle schemas

Readme

inflow-materialize

Business-friendly materialized views for Inflow Inventory data with type-safe Drizzle schemas.

Use with inflow-get to create useful views for frontend consumption.

Installation

npm install inflow-materialize inflow-get drizzle-orm

Usage

Basic Usage (Raw SQL)

import { getDb } from 'inflow-get';
import { createViews } from 'inflow-materialize';

const db = getDb('./inflow.db');
createViews(db);

// Query views with raw SQL
const lowStock = db.prepare('SELECT * FROM reorder_alerts').all();

Type-Safe Queries (Drizzle)

import Database from 'better-sqlite3';
import { drizzle } from 'drizzle-orm/better-sqlite3';
import { createViews } from 'inflow-materialize';
import { reorderAlerts, productVelocity } from 'inflow-materialize/schemas';

const sqlite = new Database('./inflow.db');
createViews(sqlite);

const db = drizzle(sqlite);

// Fully typed queries!
const alerts = db.select().from(reorderAlerts).all();
//    ^? { productId: string, sku: string | null, ... }[]

const fastMovers = db
  .select()
  .from(productVelocity)
  .where(eq(productVelocity.velocityTier, 'FAST'))
  .all();

Views

Dashboard Layer (Company-Wide)

| View | Purpose | |------|---------| | product_inventory_status | Product card with global inventory + reorder flag | | reorder_alerts | Products below reorder point with vendor + cost | | open_orders_unified | PO + SO + MO pipeline (all open work) |

Operational Layer (Location-Aware)

| View | Purpose | |------|---------| | inventory_by_location | Product summary broken out by location | | location_stock_summary | Aggregate stock value/count per location | | location_reorder_alerts | Per-location reorder points | | transfer_pipeline | Open transfers between locations |

Expert Layer (Full Granularity)

| View | Purpose | |------|---------| | inventory_detail | Inventory lines with sublocation, serial, lot | | stock_movement_ledger | UNION of all stock movements | | lot_inventory | Lot-level tracking with expiry estimation | | serial_inventory | Serial number tracking with current location |

Business Analytics

| View | Purpose | |------|---------| | customer_360 | Customer + revenue + order count + open orders | | vendor_scorecard | Vendor + products supplied + PO history | | product_margin | Product price vs vendor cost = margin | | bom_costed | Bill of materials with component costs rolled up | | category_inventory_summary | Stock value/count by category |

Time-Series / History

| View | Purpose | |------|---------| | order_history | All completed orders with line details | | product_velocity | Sales rate with 7/30/90 day windows | | dead_stock | Products with no movement in 30+ days |

API

createViews(db, options?)

Create all views in the database.

createViews(db);

// With options
createViews(db, {
  dropExisting: true,  // Drop and recreate (default: true)
  only: ['reorder_alerts', 'product_velocity'],  // Only specific views
});

dropViews(db, only?)

Drop views from the database.

dropViews(db);  // Drop all
dropViews(db, ['reorder_alerts']);  // Drop specific

Raw SQL Exports

Each view exports its SQL for direct use:

import { reorderAlertsSQL, productVelocitySQL } from 'inflow-materialize';

db.exec(reorderAlertsSQL);

Drizzle Schemas

Import from /schemas for type-safe queries:

import {
  productInventoryStatus,
  reorderAlerts,
  productVelocity,
  deadStock,
  // ... all 18 views
} from 'inflow-materialize/schemas';

Related Packages

License

ISC