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

booture

v2.1.0

Published

Application bootstrapping on top of Fluture Hooks

Downloads

165

Readme

Booture

Application bootstrapping on top of Fluture Hooks.

Booture uses Hooks (as you might expect) to ensure that whatever happens, once a service is acquired, it will always be disposed. Furthermore, acquisition and disposal of services happens at optimal parallelism.

Booture exposes a single function: bootstrap, which in combination with Fluture and Fluture Hooks, provides an ideal platform for control over your application lifecycle.

Usage

Node

$ npm install --save fluture booture fluture-hooks

On Node 12 and up, this module can be loaded directly with import or require. On Node versions below 12, require or the esm-loader can be used.

Deno and Modern Browsers

You can load the EcmaScript module from various content delivery networks:

Old Browsers and Code Pens

There's a UMD file included in the NPM package, also available via jsDelivr: https://cdn.jsdelivr.net/npm/[email protected]/dist/umd.js

This file adds booture to the global scope, or use CommonJS/AMD when available.

Usage Example

The example below defines four "services": config, postgres, redis, and app. The App depends on Redis and Postgres having been initialized, which in turn depend on the Config service.

The consumption of these services happens in the form of binding the App to a port, and waiting for SIGINT to complete the consumption.

import {Future, node, fork, attempt} from 'fluture';
import {bootstrap} from 'booture';
import {hook, acquire, runHook} from 'fluture-hooks';

const acquireConfig = (
  attempt (() => ({
    redis: {url: process.env.REDIS_URL},
    postgres: {url: process.env.POSTGRES_URL},
  }))
);

const acquirePostgres = config => (
  node (done => require ('imaginary-postgres').connect (config, done))
);

const acquireRedis = config => (
  node (done => require ('imaginary-redis').connect (config, done))
);

const closeConnection = connection => (
  node (done => connection.end (done))
);

const acquireApp = (redis, postgres) => (
  attempt (() => require ('./imaginary-app').create (redis, postgres))
);

const bootstrapConfig = {
  name: 'config',
  needs: [],
  bootstrap: () => acquire (acquireConfig),
};

const bootstrapPostgres = {
  name: 'postgres',
  needs: ['config'],
  bootstrap: ({config}) => hook (acquirePostgres (config.postgres))
                                (closeConnection),
};

const bootstrapRedis = {
  name: 'redis',
  needs: ['config'],
  bootstrap: ({config}) => hook (acquireRedis (config.redis))
                                (closeConnection),
};

const bootstrapApp = {
  name: 'app',
  needs: ['redis, postgres'],
  bootstrap: ({redis, postgres}) => acquire (acquireApp (redis, postgres)),
};

const servicesHook = bootstrap ([ bootstrapConfig,
                                  bootstrapPostgres,
                                  bootstrapRedis,
                                  bootstrapApp ]);

const withServices = runHook (servicesHook);

const program = withServices (({app}) => Future ((rej, res) => {
  const conn = app.listen (3000);
  conn.once ('error', rej);
  process.once ('SIGINT', res);
}));

fork (console.error) (console.log) (program);

Some things to note about the example above, and general usage of Booture:

  1. servicesHook is a Hook, so before running it, it can be composed with other hooks using map, ap, and chain, and even used in the definition of other bootstrappers.
  2. program is a Future, so nothing happens until it's forked. Before forking it, it can be composed with other Futures using map, ap, bimap, and chain, or any of the other functions provided by Fluture.

API

Types

type Name = String
type Services a = Dict Name a
data Bootstrapper a b = Bootstrapper {
  name :: Name,
  needs :: Array Name,
  bootstrap :: Services b -> Hook (Future c a) b
}

Functions

bootstrap :: Array (Bootstrapper a b) -⁠> Hook (Future c a) (Services b)

Given a list of service bootstrappers, returns a Hook that represents the acquisition and disposal of these services. Running the hook allows for consumption of the services.