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

@alt-stack/workers-trigger

v0.2.0

Published

Trigger.dev integration for @alt-stack/workers-core

Readme

@alt-stack/workers-trigger

Trigger.dev integration for @alt-stack/workers-core. Create type-safe background jobs with tRPC-style patterns.

Installation

pnpm add @alt-stack/workers-trigger @trigger.dev/sdk zod

Setup

  1. Follow the Trigger.dev setup guide to initialize your project.

  2. Define your worker router:

// src/workers/email.ts
import { init } from "@alt-stack/workers-trigger";
import { z } from "zod";

interface AppContext {
  db: Database;
}

const { router, procedure } = init<AppContext>();

export const emailRouter = router({
  // On-demand task
  "send-welcome-email": procedure
    .input({ payload: z.object({ userId: z.string(), email: z.string() }) })
    .task(async ({ input, ctx }) => {
      await sendEmail(input.email, "Welcome!");
    }),

  // Scheduled cron job - runs daily at 9am
  "daily-digest": procedure
    .cron("0 9 * * *", async ({ ctx }) => {
      await generateDailyDigest();
    }),
});
  1. Create the worker and export tasks:
// src/trigger/tasks.ts
import { createWorker } from "@alt-stack/workers-trigger";
import { emailRouter } from "../workers/email";
import { db } from "../db";

export const { tasks } = createWorker(emailRouter, {
  createContext: async (baseCtx) => ({
    db,
    // baseCtx.trigger contains Trigger.dev utilities
    logger: baseCtx.trigger.logger,
  }),
});

// Export individual tasks for Trigger.dev to discover
export const sendWelcomeEmail = tasks["send-welcome-email"];
export const dailyDigest = tasks["daily-digest"];
  1. Trigger tasks from your application:
// src/api/users.ts
import { tasks } from "@trigger.dev/sdk/v3";
import type { sendWelcomeEmail } from "../trigger/tasks";

export async function createUser(email: string) {
  const user = await db.users.create({ email });

  // Trigger the background job
  await tasks.trigger<typeof sendWelcomeEmail>("send-welcome-email", {
    userId: user.id,
    email: user.email,
  });

  return user;
}

Features

On-demand Tasks

const myTask = procedure
  .input({ payload: z.object({ id: z.string() }) })
  .task(async ({ input, ctx }) => {
    // Process the task
    return { processed: true };
  });

Scheduled (Cron) Jobs

const dailyJob = procedure
  .cron("0 9 * * *", async ({ ctx }) => {
    // Runs daily at 9am UTC
  });

// With timezone
const timezoneJob = procedure
  .cron({ pattern: "0 9 * * *", timezone: "America/New_York" }, async ({ ctx }) => {
    // Runs daily at 9am EST
  });

Middleware

import { createMiddleware } from "@alt-stack/workers-trigger";

const middleware = createMiddleware<AppContext>();

const loggingMiddleware = middleware(async ({ ctx, next }) => {
  ctx.trigger.logger.info(`Starting job: ${ctx.jobName}`);
  const result = await next();
  ctx.trigger.logger.info(`Finished job: ${ctx.jobName}`);
  return result;
});

const myProcedure = procedure.use(loggingMiddleware);

Error Handling

const { tasks } = createWorker(router, {
  createContext: async (baseCtx) => ({ db }),
  onError: async (error, ctx) => {
    ctx.trigger.logger.error(`Job ${ctx.jobName} failed:`, { error });
    // Send to error tracking service
    await reportError(error, { jobId: ctx.jobId });
  },
});

Context

The context (ctx) in handlers includes:

  • jobId - Unique identifier for this job execution
  • jobName - Name of the job being executed
  • attempt - Current attempt number (starts at 1)
  • trigger - The Trigger.dev context with utilities:
    • trigger.logger - Structured logging
    • trigger.wait - Wait utilities
    • trigger.run - Run metadata
  • Any custom context from createContext

API Reference

createWorker(router, options)

Creates Trigger.dev tasks from a worker router.

Options:

  • createContext - Function to create custom context for each job
  • onError - Error handler for job failures

Returns:

  • tasks - Object with all created tasks, keyed by job name