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

slambda

v0.2.0

Published

Containerized code for easy app extensibility

Downloads

21

Readme

Slambda

npm downloads npm version

Install

npm i --save slambda

Usage

const Slambda = require('slambda');

// Default values
const slambda = new Slambda({
  autoDeploy: true,
  container: {
    language: 'nodejs4.3',
    lifecycle: {
      init: () => {},
      pre: () => {},
      post: () => {},
    },
    memory: 1024,
    timeout: 10,
  },
  storage: new MemoryStore(),
  execution: new MemoryExec(),
});

// Create a container
const container = slambda.container('myapi');

// Create a method
container.method('get:user', (user) => {
  delete user.ssn;
  return user;
});

// Deploy
container.deploy();

// Call method
container
  .run('get:user', [{ id: 123, name: 'seth', ssn: '000-00-0000' }])
  .tap(user => console.log('user', user));

Chainable!? The above code can be shortened, as all methods except .run() are chainable:

// Create a container
slambda
  .container('myapi');
  .method('get:user', (user) => {
    delete user.ssn;
    return user;
  })
  .deploy()
  .run('get:user', [{ id: 123, name: 'seth', ssn: '000-00-0000' }])
  .tap(user => console.log('user', user));

Adapters

Slambda has two types of adapters, Storage and Execution.

All required adapter methods must return a Bluebird promise.

Storage

Storage adapters tell Slambda how to persist methods and containers. The default is Memory. Storage adapters can take whatever configuration they need.

Required methods:

get(String table, String id)

Returns an entity by ID

findById(String table, String index, String id)

Query table by index. Resolves to an array.

list(String table)

Resolves a list of entities from the specified table

put(String table, Object item)

Upserts an entity

delete(String table, String id)

Deletes specified entity by ID

Note: All storage adapter methods must return a Bluebird promise

Officially supported storage adapters:

  • Memory (default)
  • DynamoDB
  • FileSystem (Coming soon)
  • AWS S3 (Coming soon)
  • MongoDB (Coming soon)
  • Github (Coming soon)

Execution

Execution adapters tell Slambda how to run your code snippets. The default is Memory.

Required methods:

run(String containerId, String methodId, Array methodArguments)

Run a single method with arguments. Returns a promise with the results

deploy(Container container, Array<Method> methods)

Deploy a container and it's functions to the execution layer

execute(String containerId, Array<String id, Array arguments> calls)

Run a batch of method calls. Must return an equal length array as calls. Array order must not change.

Note: All storage adapter methods must return a Bluebird promise

Where possible, the .run() method should try to batch requests.

Officially supported execution adapters:

  • Memory (default)
  • Local (File system)
  • AWS Lambda
  • Google Cloud Functions (Coming soon)
  • Docker (Coming soon)
  • AWS EC2 (Coming soon)

API

Slambda

constructor(Object options)

Parameters

Object options

Defaults

{
  autoDeploy: true,
  container: {
    language: 'nodejs4.3',
    lifecycle: {
      init: () => {},
      pre: () => {},
      post: () => {},
    },
    memory: 1024,
    timeout: 10,
  },
  storage: new MemoryStore(),
  execution: new MemoryExec(),
}

container(String id, Object options)

Returns

Container

Parameters

String id Container ID Required

Object options Defaults to this.options.container

Container

constructor(Object options)

Parameters

Object options

Defaults

{
  language: 'nodejs4.3',
  lifecycle: {
    init: () => {},
    pre: () => {},
    post: () => {},
  },
  memory: 1024,
  timeout: 10,
}

method(String id, String|Function code)

Returns

Container

Parameters

String id Container-unique identifier for the method

String|Function code Method code.

run(String id, Array args)

Returns

Promise

Parameters

String id Method ID to run

Array args Arguments passed to method

deploy()

Deploys function to execution layer. Queues .run() commands behind deployment

Returns

Container