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

@guergabo-test/sdk

v0.3.5

Published

TypeScript SDK for Resonate

Downloads

1

Readme

Resonate is in the Design Phase

Our code base is constantly evolving as we are exploring Resonate's programming model. If you are passionate about a dead simple developer experience, join us on this journey of discovery and share your thoughts.

Join our slack

cicd codecov License

An SDK for writing simple and elegant distributed async await applications.

Why Resonate?

Resonate offers a programming model that allows you to build distributed applications using an intuitive paradigm you already know — async await.

What is Distributed Async Await?

Distributed Async Await extends the async await programming model beyond the boundaries of a single process and makes distributed computing a first-class citizen.

Features

Available now:

  • retries
  • recovery
  • schedules
  • tracing
  • logging
  • local promise store
  • remote promise store

Coming soon:

  • rate limiting
  • metrics

Let us know features you would like Resonate to support.

Install

npm install -g ts-node
npm install @resonatehq/sdk
npm install express @types/express

What's New

Schedules! You can now invoke a function on a recurring schedule. Please note, this feature is experimental and bugs are expected. If encountered please let us know.

import { Resonate, Context } from "@resonatehq/sdk";

const resonate = new Resonate();

resonate.schedule("everyMinute", "* * * * *", (ctx: Context) => {
  console.log("every minute", Date.now());
});

resonate.schedule("everyHour", "0 * * * *", (ctx: Context) => {
  console.log("every hour", Date.now());
});

resonate.start();

Getting Started

import { Resonate, Context } from "@resonatehq/sdk";
import express, { Request, Response } from "express";

type User = {
  id: number;
};

type Song = {
  id: number;
  price: number;
};

type Status = {
  charged: boolean;
  granted: boolean;
};

async function purchase(ctx: Context, user: User, song: Song): Promise<Status> {
  const charged = await ctx.run(charge, user, song);
  const granted = await ctx.run(access, user, song);

  return { charged, granted };
}

async function charge(ctx: Context, user: User, song: Song): Promise<boolean> {
  console.log(`Charged user:${user.id} $${song.price}.`);
  return true;
}

async function access(ctx: Context, user: User, song: Song): Promise<boolean> {
  console.log(`Granted user:${user.id} access to song:${song.id}.`);
  return true;
}

// Initialize Resonate app
const resonate = new Resonate();
resonate.register("purchase", purchase);

// Initialize Express app
const app = express();
app.use(express.json())

app.post("/purchase", async (req: Request, res: Response) => {
  const user = { id: req.body?.user ?? 1 };
  const song = { id: req.body?.song ?? 1, price: 1.99 };

  // id uniquely identifies the purchase
  const id = `purchase-${user.id}-${song.id}`;

  try {
    res.send(await resonate.run("purchase", id, user, song));
  } catch (err) {
    res.status(500).send("Could not purchase song");
  }
});

app.listen(3000, () => {
  console.log("Listening on port 3000");
});

Start the server.

ts-node app.ts

And call the endpoint providing a user and song id.

curl \
  -X POST \
  -H 'Content-Type: application/json' \
  -d '{"user": 1, "song": 1}' \
  http://localhost:3000/purchase

See our docs for more detailed information.

Development

npm install
npm run lint
npm test

Contributing

See our contribution guidelines.

License

The Resonate TypeScript SDK is available under the Apache 2.0 License.