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

@lensjs/core

v2.3.0

Published

The core library for Lens, providing the fundamental architecture for monitoring and debugging applications. It defines the abstract concepts of adapters, stores, and watchers, along with utilities for event emission, asynchronous context management, and

Readme

@lensjs/core

The core library for Lens, providing the fundamental architecture for monitoring and debugging applications. It defines the abstract concepts of adapters, stores, and watchers, along with utilities for event emission, asynchronous context management, and SQL formatting. This package also includes the embedded UI for the Lens dashboard.

Features

  • Lens class: The central class for initializing Lens, setting up adapters and watchers, and starting the monitoring process.
  • LensAdapter (abstract class): Defines the interface for integrating Lens with different application frameworks (e.g., Express, Adonis). It handles route registration and UI serving.
  • LensStore (abstract class): Defines the interface for data storage, allowing Lens to persist and retrieve captured events (requests, queries, cache entries). Includes methods for saving, retrieving, and truncating data.
  • LensWatcher (abstract class): Defines the interface for capturing specific types of events within an application.
  • Concrete Watchers:
    • RequestWatcher: Captures and logs details of incoming HTTP requests.
    • QueryWatcher: Captures and logs database queries.
    • CacheWatcher: Captures and logs cache interactions.
    • ExceptionWatcher: Captures and logs exceptions and errors.
  • ApiController: Provides the API endpoints for the Lens UI to fetch monitoring data.
  • lensEmitter: A global event emitter for internal communication between different parts of Lens.
  • lensContext: Utilizes AsyncLocalStorage for managing asynchronous context, primarily to associate events with a specific request ID.
  • lensUtils: A collection of utility functions, including:
    • generateRandomUuid: Generates unique IDs.
    • interpolateQuery: Interpolates SQL query placeholders with actual values.
    • formatSqlQuery: Formats SQL queries for readability.
    • getMeta: Provides __filename and __dirname in both CommonJS and ESM environments.
    • isStaticFile, stripBeforeAssetsPath: Utilities for handling static file paths.
    • prepareIgnoredPaths, shouldIgnoreCurrentPath: Logic for path-based filtering.
    • prettyHrTime: Formats high-resolution time differences.
  • BetterSqliteStore: A concrete implementation of LensStore using Better SQLite for data persistence.
  • Embedded UI: Includes a built-in web interface for visualizing captured application data.

Installation

pnpm add @lensjs/core

Usage Example (Conceptual - typically used via framework adapters)

import { Lens, RequestWatcher, QueryWatcher, CacheWatcher } from '@lensjs/core';
import { BetterSqliteStore } from '@lensjs/core/stores';
// Assuming you have a custom adapter for your framework
import MyFrameworkAdapter from './my-framework-adapter';

async function bootstrapLens(appInstance: any) {
  const store = new BetterSqliteStore();
  await store.initialize();

  const adapter = new MyFrameworkAdapter({ app: appInstance });

  await Lens.setStore(store)
    .setAdapter(adapter)
    .setWatchers([
      new RequestWatcher(),
      new QueryWatcher(),
      new CacheWatcher(),
      new ExceptionWatcher(),
    ])
    .start({
      appName: 'My Application',
      enabled: process.env.NODE_ENV !== 'production',
      basePath: 'lens-dashboard', // UI will be served at /lens-dashboard
    });

  console.log('Lens core initialized.');
}

// In your application's main entry point:
// bootstrapLens(yourFrameworkAppInstance);