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

@byzanteam/jet-queue-plugin-js

v0.5.5

Published

A JS client library for interacting with the Jet Queue plugin, supporting both plugin-based and in-memory queue mechanisms for testing and development purposes.

Readme

jet-queue-plugin-js 🚀

A JS client library for interacting with the Jet Queue plugin, supporting both plugin-based and in-memory queue mechanisms for testing and development purposes.

🌟 Getting Started

📦 Installation

Install via jsr:

import { Queue } from "@byzanteam/jet-queue-plugin-js";

📖 Usage Guide

➕ Adding Jobs to the Queue

  1. Create a queue instance:

    const defaultQueue = new Queue("default", {
      instanceName: "jetQueueInstance",
    });
  2. Add a job to the queue:

    await defaultQueue.enqueue(
      { id: 1, name: "Alice" },
      {
        meta: { slug: "unique-key" },
        unique: { fields: ["meta"], keys: ["slug", "id", "name"] },
      },
    );
  3. Use replace to update and replace:

    await defaultQueue.enqueue(
      { id: updatedProject.id },
      {
        scheduledAt: new Date(),
        unique: { fields: ["args"], keys: ["id"] },
        replace: { scheduled: ["scheduled_at"] },
      },
    );

👂 Listening for Jobs

  1. Create a job listener:

    await defaultQueue.listen(async (jobs) => {
      for (const job of jobs) {
        // Process the job
      }
    });
  2. Subscribe to multiple queues:

    const subscriber = new QueueSubscriber(
      [
        { name: "queue1", bufferSize: 20 },
        { name: "queue2", bufferSize: 15 },
      ],
      10,
      "testQueue",
    );
    
    const perform: ListenPerform<any> = async (jobs, { ack }) => {
      for (const job of jobs) {
        console.log(job);
        ack({
          type: "ack",
          payload: [{ id: job.id, queue: "queue1", code: "ok" }],
        });
      }
    };
    
    await subscriber.listen(perform);

🧪 Testing Guide

Use testing.ts for test setup and assertions in BDD frameworks.

🔧 Internal Bindings

The _internals object is created to expose the internal methods and configurations of the default queue instance for testing purposes. It includes the cancel and enqueue methods, as well as the instanceName and queue:

// queue.ts
const default = new Queue<JobArgs>("default", { instanceName: "instanceName" });

export const _internals = {
  cancel: default.cancel.bind(default),
  enqueue: default.enqueue.bind(default),
  instanceName: "instanceName",
  queue: "default",
};

⚡ Quick Setup

Test setup example:

import { setupQueue } from "@byzanteam/jet-queue-plugin-js/testing";
import { afterEach, beforeEach } from "@std/testing/bdd";
import { assertSpyCall, assertSpyCalls, stub } from "@std/testing/mock";
import { _internals } from "./queue.ts";

describe("Queue Tests", () => {
  // Setup the queue with mocking internals and testing utilities
  const { assertQueueCall, assertQueueCalls, overwritesQueueInternals } =
    setupQueue(
      "default",
      _internals,
      { beforeEach, afterEach, assertSpyCall, assertSpyCalls, stub },
    );

  // Use assertQueueCall to compare if the parameters are correct
  it("should enqueue job with correct parameters", () => {
    assertQueueCall("enqueue", 0, {
      args: [
        {
          id: existingProjectId,
        },
        {
          replace: {
            scheduled: ["scheduled_at"],
          },
          scheduledAt: new Date(),
          unique: {
            //a time period in seconds during which uniqueness will be enforced, defaults to infinity
            period: 60,
            fields: ["args"],
            keys: ["id"],
          },
        },
      ],
    });
  });

  // Use assertQueueCalls to compare if the function is called the correct number of times
  it("should call enqueue function once", () => {
    assertQueueCalls("enqueue", 1);
  });

  // Use overwritesQueueInternals to reset the mocked return value of the queue functions
  it("should overwrite queue internals for enqueue", () => {
    overwritesQueueInternals({
      enqueue: (args, _options) => {
        return Promise.resolve({
          id: bindingJobId!,
          is_conflict: true,
          args,
          queue: "default",
        });
      },
    });
  });
});

📑 Types

The enqueue API and WebSocket return job information including id, args, queue, and is_conflict:

export type QueueJobId = bigint;

export interface QueueJob<T extends Record<string, unknown>> {
  id: QueueJobId;
  args: Readonly<T>;
  is_conflict: boolean;
  queue: string;
}

export type EnqueueJobResponse = QueueJob<Record<string, unknown>>;