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

lamprox

v0.15.2

Published

Framework for development lambda-proxy function of AWS Lambda.

Downloads

60

Readme

Lamprox

Framework for development lambda-proxy function of AWS Lambda.

Setup

$ npm install lamprox

Concept and Usage

Lamprox is a minimal and flexible framework for lambda-proxy function of AWS Lambda.
When building multiple endpoints with AWS Lambda, authentication, response processing, and error handling can be applied across functions in each function.

Process

Lamprox defines a handler with multiple Process.
Process is a function as shown below.

interface Process<T, U, E> {
  (ambience: ProcessAmbience<T, E>): Promise<U | undefined>
}

interface ProcessAmbience<T, E> {
  /** Variables that pssed lambda function. */
  lambda: {
    event: APIGatewayEvent
    context: Context
    callback: ProxyCallback
  }
  /** Result that preceding process. */
  result?: T
  /** Shared variables accross that processes. */
  environments: E
}

Processor

Processor is a class that collects processes and executes them in order.
Processor holds the processes before, main, after, response, onError and executes it as a handler.

/** Preparing before main process. */
type BeforeProcess<T, E> = Process<undefined, T, E>
/** Main process for request. */
type MainProcess<T, U, E> = Process<T, U, E>
/** After process. */
type AfterProcess<U, E> = Process<U, U, E>
/** Process that creating proxy result. */
type ResponseProcess<U, E> = Process<U, ProxyResult, E>
/** Process that called when error occured. */
type OnErrorProcess<E> = Process<Error, ProxyResult, E>

interface IProcessor<T, U, E> {
  before: BeforeProcess<T, E>
  main: MainProcess<T, U, E>
  after: AfterProcess<U, E>
  response: ResponseProcess<U, E>
  onError: OnErrorProcess<E>

  toHandler: () => LambdaProxyHandler
}

Functions

Generally, it is not necessary to directly generate a processor.
Lamprox provides several functions for creating handler.

lamprox()

Create simple lambda proxy handler.
You can create a handler for lambda-proxy by simply writing a method to generate the response body.

lamprox: <U>(main: MainProcess<undefined, U, undefined>) => LambdaProxyHandler

buildHandler()

Create lambda function with various processes - befire, after, response, onError - and enviroments.
Enviroments is value shared across processes.

buildHandler: <T, U, E>(parmas: LambdaProxyHandlerBuilder.Params<T, U, E>) => LambdaProxyHandler

prepareHandlerBuilder()

prepareHandlerBuilder() is a function for creating buildHandler function.
Assuming that there are many Lambda functions, you can generate a buildHandler function that defines a common process.

prepareHandlerBuilder: <T, U, E>(preparedOptions?: ProcessorOptions<T, U, E>) => LambdaProxyHandlerBuilder<T, U, E>

Utilities

Lamprox contains node-lambda-utilities, but provides some utility functions for lambda-proxy.

generateDummyAPIGatewayEvent()

This is a function for generating a dummy APIGatewayEvent.
You can test the handler by using it together with invokeHandler() of node-lambda-utilities.

generateDummyAPIGatewayEvent: (params?: GenerateDummyAPIGatewayEvent.Params) => APIGatewayEvent

generateProcessAmbience()

A function that generates ProcessAmbience which is an argument when Process is executed.
By using this, it is possible to test each Process.

generateProcessAmbience: <T, E>(params: GenerateProcessAmbience.Params<T, E>) => ProcessAmbience<T, E>