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

@auto-engineer/narrative

v1.8.0

Published

TypeScript DSL for defining business narratives using BDD patterns with Given/When/Then syntax.

Readme

@auto-engineer/narrative

TypeScript DSL for defining business narratives using BDD patterns with Given/When/Then syntax.


Purpose

Without @auto-engineer/narrative, you would have to manually structure behavioral specifications, write boilerplate for command/query definitions, and handle the conversion between specification code and JSON models.

This package enables developers to express system behavior through narratives containing slices (commands, queries, reactions, experiences). Each slice supports client and server specifications using Gherkin-style Given/When/Then syntax.


Installation

pnpm add @auto-engineer/narrative

Quick Start

import { flow, command, specs, rule, example, type Event, type Command } from '@auto-engineer/narrative';

type OrderPlaced = Event<'OrderPlaced', { orderId: string }>;
type PlaceOrder = Command<'PlaceOrder', { productId: string }>;

flow('Orders', () => {
  command('Place order')
    .server(() => {
      specs('Order placement', () => {
        rule('Valid orders are processed', () => {
          example('User places order')
            .when<PlaceOrder>({ productId: 'p-001' })
            .then<OrderPlaced>({ orderId: 'o-001' });
        });
      });
    });
});

How-to Guides

Define a Command Slice

import { flow, command, specs, rule, example } from '@auto-engineer/narrative';

flow('Users', () => {
  command('Create user')
    .stream('user-${userId}')
    .server(() => {
      specs('User creation', () => {
        rule('Valid users created', () => {
          example('New user')
            .when({ name: 'John' })
            .then({ userId: 'u-001' });
        });
      });
    });
});

Define a Query Slice

import { flow, query, describe, it, data, source } from '@auto-engineer/narrative';

flow('Products', () => {
  query('View products')
    .client(() => {
      describe('Product list', () => {
        it('displays all products');
      });
    })
    .server(() => {
      data([source().state('Products').fromProjection('ProductsProjection', 'id')]);
    });
});

Define Data Sinks and Sources

import { flow, command, data, sink, source } from '@auto-engineer/narrative';

flow('Payments', () => {
  command('Process payment')
    .server(() => {
      data([
        sink().event('PaymentProcessed').toStream('payment-${paymentId}'),
        source().state('Account').fromProjection('Accounts', 'accountId'),
      ]);
    });
});

Load Narratives from File System

import { getNarratives } from '@auto-engineer/narrative';
import { NodeFileStore } from '@auto-engineer/file-store';

const vfs = new NodeFileStore();
const result = await getNarratives({ vfs, root: '/path/to/src' });
const model = result.toModel();

API Reference

Package Exports

import {
  flow, narrative,
  command, query, react, experience,
  specs, rule, example, describe, it, should,
  client, server, data,
  sink, source,
  getNarratives, modelToNarrative,
  addAutoIds, hasAllIds,
  gql,
  type Event, type Command, type State,
} from '@auto-engineer/narrative';

import { COMMANDS, exportSchemaCommandHandler } from '@auto-engineer/narrative/node';

Entry Points

| Entry Point | Import Path | Description | |-------------|-------------|-------------| | Main | @auto-engineer/narrative | Core DSL and types | | Node | @auto-engineer/narrative/node | Command handlers |

Slice Types

| Type | Description | Client | Server | |------|-------------|--------|--------| | command | User actions that modify state | Yes | Yes | | query | Read operations | Yes | Yes | | react | Event reactions | No | Yes | | experience | UI-only behaviors | Yes | No |

Message Types

type Event<Type extends string, Data> = { type: Type; data: Data };
type Command<Type extends string, Data> = { type: Type; data: Data };
type State<Type extends string, Data> = { type: Type; data: Data };

Architecture

src/
├── index.ts
├── node.ts
├── narrative.ts
├── fluent-builder.ts
├── schema.ts
├── types.ts
├── data-narrative-builders.ts
├── loader/
├── transformers/
├── id/
└── commands/

Key Concepts

  • Narratives: Business capabilities containing slices
  • Slices: Behavioral units (command, query, react, experience)
  • Specifications: BDD-style Given/When/Then assertions
  • Data Flow: Sinks (outbound) and Sources (inbound)

Dependencies

| Package | Usage | |---------|-------| | @auto-engineer/file-store | Virtual file system | | @auto-engineer/id | ID generation | | @auto-engineer/message-bus | Command/Event types | | zod | Schema validation | | typescript | AST parsing | | graphql | GraphQL query parsing |