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

@weegigs/events-fastify

v0.20.0

Published

Fastify services based on wee-events

Readme

@weegigs/events-fastify

Fastify server factory for wee-events service descriptions. Create HTTP APIs from event-sourced services with automatic OpenAPI documentation.

Installation

npm install @weegigs/events-fastify

Quick Start

import { create } from "@weegigs/events-fastify";
import { MemoryStore } from "@weegigs/events-core";

// Create server factory from service description
const serverFactory = create(serviceDescription);

// Create server instance
const server = await serverFactory(new MemoryStore(), {});

// Start server
await server.listen({ port: 3000 });
console.log("Server running on http://localhost:3000");

API Reference

create(description, options?)

Creates a Fastify server factory from a service description.

Parameters:

  • description: ServiceDescription - Event-sourced service description
  • options?: ServerOptions - Optional configuration

Returns: (store: EventStore, environment: Environment) => Promise<FastifyInstance>

Server Options

interface ServerOptions {
  openAPI?: boolean;           // Enable OpenAPI docs (default: true)
  errorMapper?: (error: unknown) => HttpError;  // Custom error mapping
}

Features

Automatic REST Endpoints

For a service with entity type receipt, the following endpoints are automatically created:

  • GET /receipt/{id} - Load entity by ID
  • POST /receipt/{id}/{command} - Execute command on entity

OpenAPI Documentation

OpenAPI is enabled by default and provides:

  • Schema endpoint: /openapi/schema.json - OpenAPI 3.1 specification
  • Documentation UI: /openapi/documentation - Interactive API explorer
// OpenAPI enabled (default)
const serverFactory = create(serviceDescription);

// OpenAPI disabled
const serverFactory = create(serviceDescription, { openAPI: false });

Error Handling

Customize error responses with a custom error mapper:

const customErrorMapper = (error: unknown) => {
  if (error instanceof MyBusinessError) {
    return new BadRequest(error.message);
  }
  return new InternalServerError("Something went wrong");
};

const serverFactory = create(serviceDescription, {
  errorMapper: customErrorMapper
});

Example

import { z } from "zod";
import { create } from "@weegigs/events-fastify";
import { 
  ServiceDescription, 
  LoaderDescription, 
  DispatcherDescription,
  MemoryStore 
} from "@weegigs/events-core";

// Define entity schema
const ItemSchema = z.object({
  name: z.string(),
  quantity: z.number(),
  price: z.number()
});

// Create service description
const description = ServiceDescription.create(
  { 
    title: "Inventory Service", 
    description: "Manage inventory items",
    version: "1.0.0" 
  },
  LoaderDescription.fromInitFunction(
    { type: "item", schema: ItemSchema },
    () => ({ name: "", quantity: 0, price: 0 })
  ).description(),
  DispatcherDescription.handler(
    "update", 
    ItemSchema, 
    async (env, entity, command) => {
      await env.publish(entity.aggregate, { 
        type: "updated", 
        data: command 
      });
    }
  ).description()
);

// Create and start server
const serverFactory = create(description);
const server = await serverFactory(new MemoryStore(), {});

await server.listen({ port: 3000 });

// API is now available:
// GET /item/123 - Load item
// POST /item/123/update - Update item
// GET /openapi/schema.json - OpenAPI spec
// GET /openapi/documentation - API docs

TypeScript Support

Full TypeScript support with proper type inference:

import type { ServerOptions } from "@weegigs/events-fastify";

const options: ServerOptions = {
  openAPI: true,
  errorMapper: (error) => new InternalServerError(String(error))
};

License

MIT