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

sugar-generate

v0.1.6

Published

Auto generate OAS 3.0 REST + GraphQL APIs (Node + MongoDB)

Downloads

44

Readme

Instantly Generate Rest & GraphQL APIs 🔥

Follow on Twitter Average time to resolve an issue Percentage of issues still open npm package NPM Downloads

Sugar Generator - API Edition

Install

npm i -g sugar-generate

Prereqs

if you're running mongodb locally and using the docker container, make sure to start mongo using

sudo mongod --bind_ip_all

otherwise you wont be able to connect to mongo from docker.

Getting Started

  1. Create your schema. It could be as simple as:
{
  "schema": {
    "name": {
      "type": "String",
      "default": ""
    },
    "isDead": {
      "type": "Boolean",
      "default": false
    },
    "age": {
      "type": "Number",
      "default": false
    }
  },
  "statics": {}
}

You can also provide multiple schemas like the following

[
  {
    "name": "user",
    "schema": {
      "name": {
        "type": "String",
        "default": ""
      },
      "email": {
        "type": "String",
        "trim": true,
        "required": true,
        "unique": true,
        "immutable": true
      },
      "intro": {
        "type": "Boolean",
        "default": false
      },
      "sub": {
        "one": {
          "type": "String",
          "trim": true,
          "required": true
        },
        "two": {
          "type": "String",
          "required": true
        },
        "three": {
          "type": "Number"
        }
      },
      "role": {
        "type": "String",
        "enum": ["user", "maker"],
        "default": "user"
      }
    },
    "statics": {
      "statuses": ["created", "under_review", "listed", "deleted"],
      "status": {
        "active": "active",
        "inactive": "inactive",
        "deleted": "deleted"
      }
    }
  },
  {
    "name": "team",
    "schema": {
      "name": {
        "type": "String",
        "default": ""
      },
      "users": {
        "type": "ObjectId",
        "ref": "Users"
      }
    }
  }
]

save this to monkey.json

  1. generate your api
sugar-generate \
--schema ./monkey.json \
--destination ./my-monkeys

or the short version

sugar-generate \
-s ./monkey.json \
-d ./my-monkeys

Note this is slightly different than previous versions. The schemas require a name now.

  1. Run or build the docker container and visit http://localhost:3000
cd /my-monkeys
npm i
npm start
# Or build the docker container!
docker build -t myMonkeys:0.1.0 .

running oas docs

Features 🙉

  • Generates simple Nodejs code
  • Graphql and Rest out of the box
  • Uses Mongodb with Mongoose ORM
  • Easy to build / deploy
  • Dockerfile included
  • supports multiple schemas
  • Generates CRUD APIs
    • create
    • get (many, with pagination; supports search, sort, filter, pagination out of the box)
    • getOne
    • update
    • delete
  • Generates GraphQL apis for both query and mutation

What it's good at 🙊

  • Generating an initial API
  • Microservice oriented
  • Ready to deploy (build with docker => deploy)

What it's not good at (yet) 🙈

  • idempotent changes (i.e. it doesn't know if you wrote code in there or changed things around)
  • working with modified code
  • populating table joins
  • custom actions inside controller functions

TODO

API

  • ~~basic generator rest tests~~
  • graphql tests
  • other databases?
  • your ideas?
  • middleware for auth, token validation, etc.

Graphql support

graphql mutation

graphql schema

graphql is supported and gets created by default so you can choose between rest and graphql

Graphql is on http://localhost:3000/graphql

Generated project structure

.
├── configs                 # Config File
├── connection              # DB Connections (mongo, redis)
├── controller              # Controllers
│   ├── <model name>        # Functions (one file, one function) create, delete, update, get, getOne
├── models                  # DB Models
├── router                  # Endpoint Routes
├── tests                   # Single Test File

Generated tests

** WARNING ** running the tests will pull the config file from configs/config.json and clear the DB

npm run test