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 🙏

© 2024 – Pkg Stats / Ryan Hefner

tds.pg

v0.9.0

Published

A PostgreSQL implementation for Trace-Driven State Machines (TDS).

Downloads

65

Readme

tds.pg

A PostgreSQL implementation for Trace-Driven State Machines (TDS).

Description

tds.pg is a Node.js module that provides a PostgreSQL implementation for Trace-Driven State Machines. It allows you to set up, listen to, and handle state transitions in a PostgreSQL database using the TDS approach.

Installation

To install the package, run:

npm install tds.pg

Dependencies

  • tds.ts: ^0.15.0
  • postgres: ^3.4.4

Usage

Here's a basic example of how to use the Table class:

import { Table } from "tds.pg";
import postgres from "postgres";
import { Program, Trace, Implementation } from "tds.ts";

// Create a PostgreSQL connection
const sql = postgres();

// Define your program
const X = new Program([
  new Trace("trace")
    .step("@", { output: { record: { state: "x" }, sql } })
    .step("x", { output: { record: { state: "y" }, sql } })
    .step("y", { output: { record: { state: "y" }, sql } }),
]);

// Create an implementation
const x = new Implementation(X)
  .transition("@", "x", async (it) => {
    return ["y", { ...it, record: { state: "y" } }];
  })
  .transition("x", "y", async (it) => {
    return ["@", it];
  });

// Create a Table instance
const table = new Table(sql, {
  schema: "public",
  table: "your_table_name",
  column: "state",
  program: X,
});

// Setup the table
await table.setup();

// Handle transitions
const stop = await table.handle(x);

// ... Later, when you want to stop handling
await stop();

API

Table class

The main class for interacting with the PostgreSQL implementation of TDS.

Constructor

new Table(sql, options);
  • sql: A postgres-js SQL instance
  • options: An object containing:
    • schema: The database schema name
    • table: The table name
    • column: The column name for the state
    • program: A TDS Program instance

Methods

  • setup(options): Sets up the necessary triggers and functions in the database
  • testOutputs(): Tests the outputs of the program against the database schema
  • listen(fn): Listens for state transitions and calls the provided function
  • handle(implementation): Handles state transitions using the provided implementation

Testing

The project uses Jest for testing. To run the tests:

npm test

License

This project is licensed under the MIT License.

Contributing

Contributions are welcome. Please submit pull requests or open issues on the project's GitHub repository.