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

@movenium/blocks

v2.0.18

Published

https://serverless.com/framework/docs/getting-started/

Downloads

118

Readme

Usage with serverless.com

install serverless

https://serverless.com/framework/docs/getting-started/

and create new project

https://serverless.com/framework/docs/providers/aws/guide/quick-start/

tl;dr

serverless create --template aws-nodejs --path my-service

Install

init your new project with npm init

install blocks npm install @movenium/blocks --save

Developing

https://github.com/dherault/serverless-offline

tl;dr

npm install serverless-offline --save-dev

Changes to serverless.yml

modify events (and uncomment)

events:
    - http:
        path: /{dummy}
        method: any

add to end of the file

plugins:
  - serverless-offline

use by typing serverless offline start

Basic handler.js

'use strict';

var blocks = require("@movenium/blocks/blocks");
var logger = require("@movenium/blocks/logger");

module.exports.hello = (event, context, callback) => {
    const _logger = new logger();
    
    (new blocks(_logger)).run("server.yml", {event: event}).then((response) => {
        callback(null, response);
    }, (reason) => {
        const response = {
            statusCode: 400,
            body: JSON.stringify({message: reason.message, meta: _logger.getLog(), stack: reason.stack}),
        };

        callback(null, response);
    })

};

Extending block

'use strict';
var block = require('@movenium/blocks/blocks/block');

class _block extends block {
    run() {
        // <your code here!>
    }
}

module.exports = _block;

Setting resolver

When block has settings all of them are waited and resolved before calling block's run method.

- data: 123

resolves to: 123

- data: $another.something

resolves to: "what ever is found from state.another.something"

if state.another.something is promise it will be resolved automatically and value will be the resolved value.

- data:
    test: 123
    test2: $another.something

resolves to: {test: 123, test2: "what ever is found from state.another.something"}

- data:
    test: 
      sub: $wont_be_resolved
    $test2:
      sub: $will_be_resolved

resolves to: {test: {sub: "$wont_be_resolved", test2: {sub: "what ever is found from state.will_be_resolved"}}

Sub settings can be resolved by adding $ in front of setting key

Testing

Install mocha and remember to update script test handler to package.json

"scripts": {
  "test": "mocha"
},

Pre-written mocha test handler

Pre-written test/test.js

var assert = require('assert');
var blocks = require("@movenium/blocks/blocks")

const fs = require('fs');

describe('all recorded tests', function() {

    const rerecord = false
    const runOnly = null//['recording-get_with_bad_id']
    const skipTests = ['recording-get_with_bad_id']

    let files = fs.readdirSync("recordings").filter((item) => item.startsWith("recording-")).map((item) => item.split(".")[0])
    if (runOnly) files = files.filter((item) => runOnly.indexOf(item) !== -1)
    if (skipTests) files = files.filter((item) => skipTests.indexOf(item) === -1)
    for (let i = 0; i < files.length; i++) {

        const data = fs.readFileSync("recordings/" + files[i] + ".json", "utf8")
        const test = JSON.parse(data)

        it("run '" + files[i] + "'", function (done) {

            this.timeout(5000);

            (new blocks(undefined, null)).runMocked(test.request[0], test.request[1], files[i], test.recordings, rerecord).then((response) => {
                if (rerecord) return done()
                assert.equal(test.response[0], "resolve")
                assert.deepEqual(test.response[1], response)
                done();
            }).catch((reason) => {
                if (rerecord) return done()
                if (test.response[0] !== "reject") console.log(reason)
                assert.equal(test.response[0], "reject")
                assert.deepEqual(test.response[1], reason)
                done();
            });
        })
    }

})

test by running

npm test