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

raw_lib

v1.2.9

Published

RawLib — RawQL engine, adapters and validation module

Readme

🧠 raw_lib — Modular Query, Validation & Authentication Engine for Node.js

raw_lib is a modular backend framework built around three core systems:

  • RawQL → Structured query engine
  • RawVal → Schema validation engine
  • RawAuth → Authentication & session security engine

All three are framework-agnostic, database-independent, and follow Clean Architecture principles.

It’s designed for serious backend work:

  • predictable structure
  • strict type-safety
  • reusable logic
  • cross-framework compatibility
  • minimal boilerplate

🔥 Why raw_lib?

  • 🧩 Modular & Extensible — use only RawQL, or RawAuth, or all combined
  • 🗄️ Database Independent — MongoDB, SQL, Redis, you choose
  • 🔧 Strict Query System — replace ad-hoc CRUD with structured RawQlRequest
  • 🔐 Built-in Authentication System (RawAuth)
  • 🛡️ Built-in Validation System (RawVal)
  • 🚀 Adapter-driven architecture
  • 🧰 Written in TypeScript
  • ♻️ Works in Express, Fastify, Hono, NestJS, Cloudflare Workers

📦 Installation

npm install raw_lib

📁 Core Modules

rawql/       => Structured Query Engine
rawval/      => Validation Engine
rawauth/     => Authentication Engine
adapters/    => Mongo / Redis / Future SQL adapters
types/       => Clean request & response types

🔷 RawQL — Structured Query Engine

RawQL standardizes backend data access through a typed request format.

Supported Operations

export type RawQlOperation =
  | "list"
  | "get"
  | "create"
  | "update"
  | "delete"
  | "count"
  | "aggregate";

📨 RawQlRequest

const request: RawQlRequest = {
  type: "list",
  entity: "users",
  filter: { field: "role", op: "eq", value: "admin" },
  options: {
    page: 1,
    limit: 10,
    sort: [{ field: "createdAt", direction: "desc" }],
  },
};

📬 RawQlResponse

{
  status: true,
  message: "Fetched users successfully",
  data: {
    type: "paginated",
    items: [...],
    totalItems: 42,
    currentPage: 1,
    totalPages: 5
  }
}

🧩 RawQL MongoAdapter Example

import MongoAdapter from "raw_lib/rawql/adapters/mongo_adapter";
import { RawQlEngine } from "raw_lib/rawql";

const adapter = new MongoAdapter("mongodb://localhost/mydb");

// Register Mongoose schemas
adapter.registerModel("users", userSchema);
adapter.registerModel("todos", todoSchema);

const engine = new RawQlEngine(adapter);

const response = await engine.execute({
  type: "get",
  entity: "users",
  filter: { field: "username", op: "eq", value: "raunak" },
});

🛡️ RawVal — Validation Engine

import { RawValEngine } from "raw_lib/rawval";
import { z } from "zod";

const val = new RawValEngine();

val.register("users", {
  create: {
    username: z.string().min(3),
    email: z.string().email(),
    password: z.string().min(6),
  },
});

Validation is fully optional but recommended.


🔐 RawAuth — Authentication & Device Session Engine

RawAuth is a database-agnostic authentication module that plugs directly into RawQL and handles:

  • 🔑 Password login
  • ✉️ Email & phone OTP login
  • 📱 Device-based session tracking
  • 🪪 Short-lived JWT issuing
  • 🕵️ Token verification with fingerprint matching
  • 🚫 Revoking sessions / logout
  • 🔒 OTP storage with hashing + expiry
  • 🧪 Provider-agnostic OTP delivery (SMS/Email via Twilio, SendGrid, etc.)

RawAuth does not touch the database directly.

It calls RawQL, which calls your adapter (Mongo/SQL/Redis…).


⚙️ RawAuth Usage Example (Mongo + Express)

import express from "express";
import {MongoAdapter} from "raw_lib";
import {RawQlEngine} from "raw_lib";
import { RawAuthEngine } from "raw_lib";

const mongo = new MongoAdapter("mongodb://localhost:27017/rawlib");
mongo.registerModels("User", userSchema); // users, deviceSessions, otpCodes schemas

const rawql = new RawQlEngine(mongo);

const auth = new RawAuthEngine({
  rawql,
  jwtSecret: process.env.JWT_SECRET,
});

const app = express();
app.use(express.json());

// fingerprint helper
const fp = (req) => ({
  deviceId: req.headers["x-device-id"],
  userAgent: req.headers["user-agent"],
  ip: req.ip,
});

// password login
app.post("/auth/login", async (req, res) => {
  const resp = await auth.loginWithPassword({
    identifier: req.body.identifier,
    password: req.body.password,
    fingerprint: fp(req),
  });
  res.json(resp);
});

// verify token
app.get("/protected", async (req, res) => {
  const token = req.headers.authorization?.split(" ")[1];
  const resp = await auth.verifyToken(token, fp(req));
  res.status(resp.status ? 200 : 401).json(resp);
});

🔢 OTP Flow Example

app.post("/auth/otp/send", async (req, res) => {
  const resp = await auth.sendOtp(req.body.contact);
  res.json(resp); // returns { status, data: { otpId } }
});

app.post("/auth/otp/verify", async (req, res) => {
  const resp = await auth.verifyOtp(req.body.otpId, req.body.code);
  res.json(resp);
});

You can plug in a real provider:

  • Twilio SMS
  • SendGrid Email
  • AWS SES
  • Firebase Phone Auth

RawAuth stays the same — only the provider changes.


🧠 Example Use Cases

  • Build Firebase-like backend with database & auth abstraction
  • Strict and predictable authentication without framework lock-in
  • Enforce device-based session integrity
  • Replace REST CRUD with structured RawQL queries
  • Use one generic controller to process all entity actions
  • Create backend SDKs for frontend apps
  • Build internal tools with full type safety

🚀 Roadmap

RawQL

  • [x] MongoDB Adapter
  • [ ] SQL Adapter
  • [ ] Redis Adapter
  • [ ] GraphQL Transport Layer
  • [ ] Socket Adapter

RawVal

  • [x] Base Validation Engine
  • [ ] Auto-schema generation
  • [ ] DTO generator for frontend

RawAuth

  • [x] User + Device Session Model
  • [x] Password login
  • [x] OTP login
  • [x] JWT issuing
  • [x] Token verification + fingerprint check
  • [ ] OAuth providers (Google, Apple, GitHub)
  • [ ] RBAC / Roles integration with RawQL
  • [ ] Multi-tenant auth

✍️ Author

Made with ❤️ by Raunak Pandey

GitHub: https://github.com/raunak-dows17


📄 License

MIT — free for commercial and open-source use.