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

@ayanaware/bento

v1.0.0-rc.29

Published

Modular runtime framework designed to solve complex tasks

Downloads

899

Readme

@ayanaware/bento npm (scoped) Discord install size

DocumentationExamples

Bento is an application framework designed to help with creating and maintaing modular projects.

The Goal

Assist developers with common patterns used in modular codebases. While staying out of their way, minimal headaches, minimal debt.

The Promises

  • Readability First: Bento's Code should be well documented and easy to read.
  • Limited Dependencies: Solve problems by writing code, Not adding dependencies.
  • Tests all the things: Catch some bugs before they get out.

Stuff Bento does

  • Plugable application framework.
  • Featuring: Components, Events, Plugins, Properties, Variables
  • Component and Plugin lifecycle management
  • Consistent Component API
  • Defines strict, opinionated, rules

Stuff Bento does not do

  • Bento should work in the browser, but it is not a website framework.

Install

yarn add @ayanaware/bento
npm i @ayanaware/bento

What is a Bento Component?

Bento indroduces a concept of components. Components are logical chunks of code that all work together to provide your application to the world.

All components recieve their own ComponentAPI instance. The Component API is consistent across all components and provides a way for components to speak to eachother. As well as many other "Quality of life" features. Such as: Dependency resolution and injection, Variable injection, component events, and more!

As a rule of thumb, components should not take on more then required. (IE: instead of having one component for connecting to Discord and processing messages. Have two, one for the connection and emitting the message events, and one that handles messages)

Here is a very basic example of a Bento component:

import { Component, ComponentAPI } from '@ayanaware/bento';

export class Basic implements Component {
	// required for all components, must be unique
	public name = 'Basic';
	// this property becomes available after onLoad see ComponentAPI for more info
	public api!: ComponentAPI;

	// Optionally define other components we depend upon
	// Some decorators auto append to this array such as @Subscribe
	public dependencies: Array<Component> = [];

	// Lifecycle event, called right before component fully loaded
	public async onLoad() {
		console.log('Hello world!');
	}

	// Lifecycle event, called right before component is unloaded
	public async onUnload() {
		console.log('Goodbye world!');
	}
}

A runnable version of this example is available on Gitlab

How to use Bento

Getting started with Bento is pretty simple. First import and initilize Bento and any plugins you wish to use. Then simply add the plugins to Bento. The below example assumes you have a directory called "components" in the same directory (relative) to it.

import { Bento, EntityType, FSEntityLoader } from '@ayanaware/bento';

// Create a Bento instance
const bento = new Bento();

// Anonymous async function so we can use await
(async () => {
	// Create FSEntityLoader
	// NOTE: Keep in mind all FSEntityLoader does is
	// find components in a path, instantiates them and
	// calls Bento.addComponent() behind the scenes
	const fsel = new FSEntityLoader();
	await fsel.addDirectory([__dirname, 'components'], EntityType.COMPONENT);

	// Apply plugin to Bento.
	await bento.addPlugin(fsloader);

	// Verify that Application looks good to continue
	await bento.verify();
})().catch(e => {
	console.error(`Error while starting Bento:\n${e}`);
	process.exit(1);
});

Bento Application

Application makes it even easier to bootstrap Bento Applications. Behind the scenes FSEntityLoader is used to find plugins and components in ./plugins and ./components respectively. Variables are also loaded using VariableFileLoader from ../env.example.json and ../env.json. Finally bento instance and afformentioned plugins are completely exposed in cases when you need them.

import { Application } from '@ayanaware/bento';

// Bento Application Helper
const app = new Application();

// Anonymous async function so we can use await
(async () => {
	// Default Variables are loaded from `../env.example.json`
	// Variables are loaded from `../env.json`
	// Plugins in `./plugins` are instantiated and added to Bento
	// Components in `./components` are instantiated and added to Bento
	// All this behavior can be modifed using cfg in Application constructor
	await app.start();

	// Must be called, calls `bento.verify();` and returns `ApplicationState`
	await app.verify();
})().catch(e => {
	console.error(`Error while starting Application:\n${e}`);
	process.exit(1);
});

More examples available here

Testimonials

Below are a few people raving about using Bento!

So far Bento has been nothing but good memories in production, it does its job very very well, we've scaled to 40k Guilds, 10 shards a cluster and Bento makes life with scaling less scary. -- Plexi Development (captchabot.xyz)