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

@spaceteams/warp-als

v1.4.1

Published

Async local storage middleware for Warp

Readme

@spaceteams/warp-als

AsyncLocalStorage middleware for warp — expose context to legacy code.

Bridges warp's explicit context into Node.js AsyncLocalStorage, making request-scoped values accessible from code that can't receive parameters directly.


Motivation

Warp passes context explicitly through function parameters — but not every piece of code can receive it that way. Express middleware, ORM hooks, logging libraries, and other framework internals often rely on implicit ambient context. @spaceteams/warp-als bridges this gap by exposing selected parts of the warp context via AsyncLocalStorage, making them accessible anywhere in the async call chain.


Installation

pnpm add @spaceteams/warp-als

Peer dependency: @spaceteams/warp


Usage

Creating the ALS bridge

Call createWarpAls with your context and exposed-context types:

import { createWarpAls, type AlsOptions } from "@spaceteams/warp-als";

type AppContext = { requestId: string; userId: string; db: Database };
type ExposedContext = { requestId: string; userId: string };

const { middleware, getCtx } = createWarpAls<AppContext, ExposedContext>();

Registering the middleware

import { buildRuntime, callable } from "@spaceteams/warp";

const { resolve, component } = buildRuntime()
  .use(middleware())
  .provide({ db: createDb() })
  .require<{ requestId: string; userId: string }>();

Declaring the extract function per component

Pass als in the callable/usecase meta with an extract function that selects the context slice to expose:

type RunOptions = Partial<AlsOptions<AppContext, ExposedContext>>;

const createOrder = callable<AppContext, [string], Order, RunOptions>(
  {
    name: "create-order",
    als: { extract: (ctx) => ({ requestId: ctx.requestId, userId: ctx.userId }) },
  },
  (ctx) => async (productId) => {
    const order = await ctx.db.insertOrder(productId);
    legacyAuditLog("order-created"); // can access context via getCtx()
    return order;
  },
);

Components without als in their meta pass through unchanged — the middleware is a no-op.

Accessing context from anywhere

Call getCtx() from any code running within the async scope:

function legacyAuditLog(action: string) {
  const ctx = getCtx();
  if (ctx) {
    logger.info({ requestId: ctx.requestId, userId: ctx.userId, action });
  }
}

getCtx() returns undefined outside of a warp component scope.


API

createWarpAls<Ctx, ExposedCtx>()

Creates a scoped ALS instance. Returns:

| Member | Type | Description | |--------|------|-------------| | middleware() | Middleware<Ctx, AlsOptions<Ctx, ExposedCtx>> | Warp middleware — register with .use(middleware()) | | getCtx() | () => ExposedCtx \| undefined | Retrieves the stored context for the current async scope |

AlsOptions<Ctx, ExposedCtx>

type AlsOptions<Ctx, ExposedCtx> = {
  als: {
    extract: (ctx: Ctx) => ExposedCtx;
  };
};

RunOptions shape. The extract function selects which parts of Ctx to expose via AsyncLocalStorage.


License

MIT