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

lr-main

v2.0.6

Published

The core for everything lagoon-road

Downloads

20

Readme

lr-main reference

Changelog in v2.0.1

  • Simplified code and usage, reduced package by almost 90% to 1.3KB
  • Parallel processing, speeding up and non blocking
  • Removed the complete next callback, working with returns
  • Simpler interface, no more relay, you have control over the complete road at runtime
  • Dynamic assignment of callbacks (previously middleware) is now possible
  • Extensions are not so deeply nested anymore
  • Removed the updateable extensions, now just pass in the road object to an extension

The lr-main package is the only mandatory package for Lagoon road. This package connects everything together, regardless of environment.

| Information | - | | ----------- | - | | Code coverage | Coverage Status | | Repo link | lr-main | | Dependencies | check-types | | Size (Gzip)| 1.3KB | | Version | 2.0.0 | | License | MIT | | Usage | guide |


core(environmentId)

const road = require('lr-main')('webserver');

environmentId:string
The primary environment id for the road, this is the executing environment that will be used when an update event is fired.


road.parser(parser)

const parser = require('lr-url-parser')();
road.parser(parser);

parser:object
The parser that you want to use to parse an incoming matchValue. It expects two functions in the object, add and parse. Read more about parsers in the guide


road.extension(extensionId, extension)

road.extension('router', router, true);

extensionId:string
A unique id to identify the extension.

extension:*
The actual extension, this can be any type of code that you want to use

Extensions are available on the road object in the callback

module.exports = road => {
  console.log(road.extensionName);
}

road.callback(id, callbackFunction)

road.callback('debug', road => { console.log(road) });

id:string
Unique id to identify the current callback function

callbackFunction:function The actual function that you want to call, it will have the road as parameter and some optional paramaters that might have been given by the update event.

module.exports = road => {
  // body
  return { key : value } // Return an object, this will be added to the road object
}

road.where(environmentId, [...environmentId])

road.where('webserver', 'client');

environmentId
The where method expects at least one argument, which should be a string. This is an environment id to which all the following callback will be assigned. If you want to assign callback to multiple environments you can just specify several ids like in the example above.


road.run(matchValue, callbackId, [matchValue])

road
  .run('*', 'log');          // All matches
  .run('/some-url', 'log');  // This specific match
  .run('-/some-url', 'log'); // Everything except this match

matchValue:string
A match value in most webapps can be thought of as an url path, but it is not limited to paths only. Frankly it can be any string you can think of, even a JSON string to match on JSON content. Or in an even more exotic example you can match Raspberry Pie sensor outputs via an extension to string values and let that trigger callbacks. You can use the * as a wildcard to match on all match values that might come in or - if you want to run it on all the paths except the given one.

callbackId:string
Identifier you added by using the callback method. It needs to be a string and should match to a callback function, otherwise it will throw an error.

[updateType:string]
The update type is an extra layer for matching callback, if we use a http protocol to update the road, this will be the method for the request. By default it wil be GET because it is the most common, but it can be overwritten to be something else. Again you are not limited to http methods, it fully depends on what an extension sends out via an update event.


road.fail(callbackId)

road.fail('log')

Whenever a callback throws an error, it will be redirected to error callback. You can use it to render alternative content or log the errors. The road object will have a new property error with the error. The fail method will also be called when no callbacks could be found for the current matchValue.

callbackId:string
Identifier you added by using the callback method. It needs to be a string and should match to a callback function, otherwise it will throw.


road.update(options:object, [...parameters])

road.update({ matchValue : '/somepath', updateType : 'post' }, parameterOne, parameterTwo);

Manually trigger an update event to the road by calling the update method.

options.matchValue:string
A match value in most webapps can be thought of as an url path, but it is not limited to paths only. Frankly it can be any string you can think of, even a JSON string to match on JSON content. Or in an even more exotic example you can match Raspberry pie sensor outputs via an extension to string values and let that trigger callback. You can use the * as a wildcard to match on all match values that might come in.

options.updateType:string
The update type is an extra layer for matching callback, if we use a http protocol to update the road, this will be the method for the request. By default it wil be GET because it is the most common, but it can be overwritten to be something else. Again you are not limited to http methods, it fully depends on what an extension sends out via an update event.

parameters:*
Each update can be have custom parameters that will be available as callback arguments. This could be for example the request and response object on a router update.

Road object

The road object is passed from callback function to callback function.

road.parameters:object

If you are using a parser that supplies you with parameters like lr-url-parser, you can access them via road.parameters.

road.update(options:object):function

See update method for usage.

road.callbacks:object

All the callbacks that are assigned.

other

There are more properties on the road object, do a dump to see an overview of all properties and methods.