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

@parsrun/service

v0.1.33

Published

Unified service layer for extracted microservices - RPC + Events

Downloads

1,915

Readme

@parsrun/service

Unified service layer for building microservices with RPC, Events, and Distributed Tracing.

Features

  • RPC Layer - Type-safe request-response communication
  • Event Layer - CloudEvents-compatible async messaging
  • Resilience - Circuit breaker, bulkhead, retry, timeout
  • Tracing - W3C Trace Context compatible distributed tracing
  • Multi-Transport - Embedded, HTTP, Cloudflare (Workers, DO, Queues)

Installation

pnpm add @parsrun/service @parsrun/core

Quick Start

Define a Service

import { defineService } from "@parsrun/service";

export const emailService = defineService({
  name: "email",
  version: "1.0.0",
  queries: {
    getTemplates: {
      input: undefined,
      output: { templates: "array" },
    },
  },
  mutations: {
    send: {
      input: {
        to: "string",
        subject: "string",
        html: "string",
      },
      output: {
        success: "boolean",
        messageId: "string?",
      },
    },
  },
  events: {
    emits: {
      "email.sent": {
        data: { messageId: "string", to: "string" },
      },
      "email.failed": {
        data: { error: "string", to: "string" },
      },
    },
  },
});

Use a Service (Client)

import { useService } from "@parsrun/service";

// Get service client
const email = useService("email");

// Make RPC calls
const result = await email.mutate("send", {
  to: "[email protected]",
  subject: "Hello",
  html: "<p>Hello World</p>",
});

// Subscribe to events
email.on("email.sent", async (event) => {
  console.log("Email sent:", event.data.messageId);
});

Modules

RPC

Request-response communication between services.

import {
  RpcClient,
  RpcServer,
  createRpcClient,
  createRpcServer,
  EmbeddedTransport,
  HttpTransport,
} from "@parsrun/service/rpc";

// Create server
const server = createRpcServer({
  service: "email",
  handlers: {
    send: async (input, ctx) => {
      // Handle request
      return { success: true, messageId: "123" };
    },
  },
});

// Create client
const client = createRpcClient({
  service: "email",
  transport: new EmbeddedTransport(server),
});

// Call method
const result = await client.call("send", {
  to: "[email protected]",
  subject: "Hello",
  html: "<p>Hello</p>",
});

Events

Asynchronous event-driven communication.

import {
  EventEmitter,
  createEventEmitter,
  MemoryEventTransport,
  createMemoryEventTransport,
} from "@parsrun/service/events";

// Create transport
const transport = createMemoryEventTransport();

// Create emitter
const emitter = createEventEmitter({
  service: "email",
  transport,
});

// Emit event
await emitter.emit("email.sent", {
  messageId: "123",
  to: "[email protected]",
});

// Subscribe to events
transport.subscribe("email.*", async (event, ctx) => {
  console.log("Event received:", event.type, event.data);
});

Resilience

Patterns for building resilient systems.

import {
  CircuitBreaker,
  Bulkhead,
  withRetry,
  withTimeout,
  TimeoutExceededError,
} from "@parsrun/service/resilience";

// Circuit Breaker
const cb = new CircuitBreaker({
  failureThreshold: 5,
  resetTimeout: 30000,
  successThreshold: 2,
});

const result = await cb.execute(async () => {
  return await fetch("https://api.example.com/data");
});

// Bulkhead (concurrency limiting)
const bulkhead = new Bulkhead({
  maxConcurrent: 10,
  maxQueue: 100,
});

await bulkhead.execute(async () => {
  // Limited concurrent execution
});

// Retry with backoff
const fetchWithRetry = withRetry(
  async () => fetch("https://api.example.com/data"),
  {
    attempts: 3,
    backoff: "exponential",
    initialDelay: 100,
    maxDelay: 5000,
    shouldRetry: (error) => error.retryable !== false,
  }
);

// Timeout
const fetchWithTimeout = withTimeout(
  async () => fetch("https://api.example.com/data"),
  5000
);

Tracing

W3C Trace Context compatible distributed tracing.

import {
  Tracer,
  createTracer,
  ConsoleExporter,
  OtlpExporter,
} from "@parsrun/service/tracing";

// Create tracer
const tracer = createTracer({
  serviceName: "email-service",
  serviceVersion: "1.0.0",
  exporter: new ConsoleExporter(),
});

// Trace an operation
const result = await tracer.trace("send-email", async (span) => {
  span?.attributes["email.to"] = "[email protected]";
  // ... send email
  return { success: true };
});

// Manual span management
const span = tracer.startSpan("process-webhook", { kind: "server" });
try {
  // Process webhook
  tracer.endSpan(span);
} catch (error) {
  tracer.endSpan(span, error);
  throw error;
}

Cloudflare Transports

Native Cloudflare Workers integration.

import {
  WorkerRpcTransport,
  DurableObjectTransport,
  QueueEventTransport,
} from "@parsrun/service/transports/cloudflare";

// Service Binding (Worker-to-Worker RPC)
const transport = new WorkerRpcTransport({
  binding: env.EMAIL_SERVICE, // Service binding
});

// Durable Object RPC
const doTransport = new DurableObjectTransport({
  namespace: env.EMAIL_DO,
  idGenerator: (req) => req.tenantId,
});

// Queue-based Events
const queueTransport = new QueueEventTransport({
  queue: env.EVENTS_QUEUE,
});

Configuration

import { mergeConfig, createDevConfig, createProdConfig } from "@parsrun/service";

// Development config
const devConfig = createDevConfig({
  resilience: {
    circuitBreaker: { enabled: false }, // Disable for debugging
  },
  tracing: {
    enabled: true,
    sampler: "always", // Trace everything
  },
});

// Production config
const prodConfig = createProdConfig({
  resilience: {
    circuitBreaker: {
      failureThreshold: 5,
      resetTimeout: 30000,
    },
    bulkhead: {
      maxConcurrent: 100,
    },
  },
  tracing: {
    enabled: true,
    sampler: { ratio: 0.1 }, // Sample 10% of requests
  },
});

Sub-path Imports

// Main entry (everything)
import { defineService, useService } from "@parsrun/service";

// Specific modules
import { RpcClient, RpcServer } from "@parsrun/service/rpc";
import { EventEmitter, MemoryEventTransport } from "@parsrun/service/events";
import { CircuitBreaker, withRetry } from "@parsrun/service/resilience";
import { Tracer, createTracer } from "@parsrun/service/tracing";
import { jsonSerializer } from "@parsrun/service/serialization";
import { WorkerRpcTransport } from "@parsrun/service/transports/cloudflare";

API Reference

Core

| Export | Description | |--------|-------------| | defineService(def) | Define a service with queries, mutations, events | | useService(name, options?) | Get a service client | | ServiceRegistry | Manage multiple service instances |

RPC

| Export | Description | |--------|-------------| | RpcClient | Client for making RPC calls | | RpcServer | Server for handling RPC requests | | EmbeddedTransport | In-process transport (testing/monolith) | | HttpTransport | HTTP-based transport | | createHttpHandler(server) | Create HTTP request handler |

Events

| Export | Description | |--------|-------------| | EventEmitter | Emit CloudEvents-compatible events | | EventHandlerRegistry | Register event handlers | | MemoryEventTransport | In-memory transport | | GlobalEventBus | Cross-service event bus | | DeadLetterQueue | Store failed events |

Resilience

| Export | Description | |--------|-------------| | CircuitBreaker | Fail fast when service is unhealthy | | Bulkhead | Limit concurrent requests | | withRetry(fn, options) | Retry failed operations | | withTimeout(fn, ms) | Add timeout to operations | | TimeoutExceededError | Timeout error class |

Tracing

| Export | Description | |--------|-------------| | Tracer | Main tracing class | | createTraceContext() | Create W3C trace context | | ConsoleExporter | Export spans to console | | OtlpExporter | Export spans to OTLP endpoint | | SpanAttributes | Standard span attribute names |

License

MIT