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

@hawkstow/sfr

v1.8.15

Published

An opinionated way of writing services using ExpressJS.

Downloads

1,013

Readme

Single File Router (SFR)

Overview

SFR allows the declaration of services including its controllers, handlers and validators in one single file.

Featuring a configurable Inversion of Control pattern for dependency libraries, It allows developers to easily inject dependencies on either handlers or controllers for convenient and easy access.

Due to it's self-contained and structured format, The SFR has allowed for the development of several extensions such as:

  • OpenAPI Service Translator

    A plugin which also uses API-Bundler's ability to extract metadata from individual SFRs It's main purpose is to translate and create service-level documentation which follows the OpenAPI Standard, this essentially opens up doors to extensive tooling support, instrumentation, automated endpoint testing, automated documentation generation, just to name a few.

  • UAC - ACM Self-Registration Scheme

    The in-house API-Bundler was designed to extract useful information from individual SFRs, termed service-artifacts, they are reported to a centralized authority through the well-documented UAC - ACM Self-Registration Scheme, this is prerogative to the grand scheme of Resource Administration.

Structure

A regular SFR is composed of the following objects

|Object Name|Description| |-|-| |CFG| configuration information relayed to the API-bundler (service-parser).| |Validators|POJO representation of what values are allowed for each endpoint.| |Handlers| Express middlewares which acts as the main logic block for each endpoint.| |Controllers|Functions that execute calls to the database.|

Usage


import sfr from "@hawkstow/sfr";
import express from "express";

const api_path = "api";
const doc_path = "docs";

const app = express();

/*
	Note: 
	SFR Bundler will look for two folders, named "rest" and "ws" inside the "path". 
	The placement of SFRs define the protocol that they'll use. 
	`
	i.e:rest SFRs reside within "rest", websocket SFRs reside in "ws".
*/

sfr({
  root : "dist",   //Specifies the working directory
  path : api_path, //Specifies the API directory i.e: where SFR files reside
  out  : doc_path  //Specifies the directory for the resulting OAS documents
}, app);

Error-Handling

The library automatically handles errors on both handlers and controllers, however, care must be taken on how error-handling is done by the developer, the following table illustrates what error-handling styles are allowed for both cases.

|Handlers|Controllers| |-|-| |Exception Throws|Promise.resolve/reject returns| |Passing Exceptions to Next fn||

Bug Reporting

If you've found a bug, please file it in our Github Issues Page so we can have a look at it, perhaps fix it XD

TODO:

  • Multer Upload Validation
  • Built-in Logging