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

stucco-js

v0.10.19

Published

![image](https://user-images.githubusercontent.com/779748/217842393-67c3d172-8039-490d-b315-e208a68f89ae.png)

Downloads

468

Readme

image

Javascript runtime for Stucco

Build

About

Stucco-js is JavaScript/TypeScript runtime for Stucco. It can be used as a local development environment or as a base library for implementing FaaS runtime.

Configuration file

Stucco-js relies on Stucco library written in GoLang. Configuration file format is in JSON.

Resolvers

{
    "resolvers":{
        "RESOLVER_TYPE.RESOLVER_FIELD":{
            "resolve":{
                "name": "PATH_TO_RESOLVER"
            }
        }
    }
}

Custom Scalars

{
    "scalars":{
        "CUSTOM_SCALAR_NAME":{
            "parse":{
                "name": "PATH_TO_RESOLVER"
            },
            "serialize":{
                "name": "PATH_TO_RESOLVER"
            }
        }
    }
}

Handler

You can also return Promise from handler

Default export

module.exports = (input) => {
    return  "Hello world"
}

Handler export

module.exports.handler = (input) => {
    return "Hello world"
}

Named export

module.exports.someName = (input) => {
    return "Hello world"
}
{
    "resolvers":{
        "RESOLVER_TYPE.RESOLVER_FIELD":{
            "resolve":{
                "name": "PATH_TO_RESOLVER.someName"
            }
        }
    }
}

Passing arguments to another resolver

Resolver "Query.todoOperations"

type TodoOperations{
    getCreditCardNumber(id: String!): String
    showMeTehMoney: Int
}

type Query{
    todoOps: TodoOperations
}
{
    "resolvers":{
        "Query.todoOps":{
            "resolve":{
                "name": "lib/todoOps"
            }
        },
        "TopoOps.getCreditCardNumber":{
            "resolve":{
                "name": "lib/getCreditCardNumber"
            }
        }
    }
}

lib/todoOps.js

module.exports = (input) => {
    return {
        response:{
            creditCards:{
                dupa: "1234-1234-1234-1234",
                ddd: "1222-3332-3323-1233"
            }
        }
    }
}

lib/getCreditCardNumber.js

module.exports = (input) => {
    const { id } = input.arguments
    return {
        response: input.source.creditCards[id]
    }
}

Example

Basic

schema.graphql

type Query{
    hello: String
}
schema{
    query: Query
}

stucco.json

{
    "resolvers":{
        "Query.hello":{
            "resolve":{
                "name": "lib/hello"
            }
        }
    }
}

lib/hello.js

export function handler(input){
    return "Hello world"
}

Test query

{
    hello
}
{
    "hello": "Hello world"
}

This JSON defines resolver

Using TypeScript

So if you have your TypeScript files in src folder you should transpile them to the lib folder and stucco can run it from there.

Local development

To start local development you need stucco.json, schema.graphql, file with resolvers in the root folder and inside root folder. To fetch your schema from URL you can use tool like graphql-zeus

Add this script to your package json to test your backend

{
    "scripts":{
        "start": "stucco"
    }
}

Or run with npx

npx stucco