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

@feedloop/foundry

v0.3.0

Published

Provides commonly-used data structures suitable for distributed applications thanks to foundationdb.

Downloads

35

Readme

FOUNDRY

Provides commonly-used data structures suitable for distributed applications thanks to foundationdb.

Usage

Installation

Before installing the package, you need to install the foundationdb client on your machine. Please follow this guide to install it.

Install foundry with your package manager:

Using npm

npm install --save @feedloop/foundry

Using yarn

yarn add @feedloop/foundry

Initialization

Foundry uses nodejs foundationdb client that looks for configs in several ways.

Set FDB_API_VERSION to your environment variable to select the foundationdb api version, defaults to version 620.

import Foundry from "@feedloop/foundry";

// somewhere in your async scope
const foundry = await Foundry.init("your-database-name");

Usage

import { Set } from "@feedloop/foundry";

// somewhere in your async scope
const hasBar = await foundry.exec(async (factory) => {
  const set = factory.open(Set, "my-set");
  await set.add("foo", "bar", "baz");
  return set.has("bar");
});

// hasBar will be `true`

All foundry's operations must be run within the foundry.exec scope because they will run in the same transaction. Each transaction will be re-run when a conflict is detected, so keep it simple to reduce client overhead.

Available Data Structures

Foundry provides commonly used data structures suitable for distributed applications by utilizing foundationdb's transaction excellence.

List

import { List } from "@feedloop/foundry";

// somewhere in your async scope
await foundry.exec(async (factory) => {
  const list = factory.open<List<string>>(List, "list1");
  await list.push("a", "b", "c"); // ["a", "b", "c"]
  const secondItem = await list.at(1); // returns "b"
  const last = await list.pop(); // returns "c"
  const len = await list.length(); // returns 2
});

Set

import { Set } from "@feedloop/foundry";

// somewhere in your async scope
await foundry.exec(async (factory) => {
  const set = factory.open(Set, "my-set");
  await set.add("foo", "bar", "baz"); // ["foo", "bar", "baz"]
  await set.remove("bar"); // ["foo", "baz"]
  await set.size(); // 2
});

Map

import { Map } from "@feedloop/foundry";

// somewhere in your async scope
await foundry.exec(async (factory) => {
  const map = factory.open(Map, "my-map");
  await map.set("foo", 1); // {foo: 1}
  await map.set("bar", 2); // {foo: 1, bar: 2}
  await map.delete("bar"); // {bar: 2}
  await map.size(); // 2
});

PersistentQueue

import { PersistentQueue } from "@feedloop/foundry";

// somewhere in your async scope
await foundry.exec(async (factory) => {
  const queue = factory.open(PersistentQueue, "my-queue");
  await queue.write("foo"); // ["foo"]
  await queue.write("bar"); // ["foo", "bar"]

  // reader1 consuming messages
  await queue.read("reader1", 1, true); // returns ["foo"]
  await queue.readOffset("reader1"); // returns 1
  await queue.read("reader1", 1, true); // returns ["bar"]
  await queue.read("reader1", 1, true); // returns []
  await queue.readOffset("reader1"); // returns 2

  // reader2 consuming messages
  await queue.read("reader2", 2, true); // returns ["foo", "bar"]
  await queue.read("reader2", 2, true); // returns []
  await queue.size(); // return 2
});

CronJob

import { CronJob } from "@feedloop/foundry";

// somewhere in your async scope
// set a cron schedule
await foundry.exec(async (factory) => {
  const cronjob = factory.open(CronJob, "my-cronjob");
  // At every 5th minute (https://crontab.guru/#*/5_*_*_*_*)
  await cronjob.schedule("5 * * * *");
});

// setup a polling to check for jobs
setInterval(async () => {
  const hasJob = await foundry.exec(async (factory) => {
    const cronjob = factory.open(CronJob, "my-cronjob");
    return cronjob.take();
  });
  if (hasJob) {
    console.log("I have a job!"); // will run at every 5th minute
  }
}, 1000 * 60); // run every 1 minute