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

scam

v0.1.6

Published

Simple schema-based REST API on node and SQLite, with fully functional CRUD flows.

Downloads

10

Readme

Scam

Simple schema-based REST API on node and SQLite, with fully functional CRUD flows.

  • Source: https://github.com/Eiskis/scam
  • Demo project: https://github.com/Eiskis/scam-demo
  • Demo project deployed to Heroku: https://scam-demo.herokuapp.com/

Scam is not suitable for production use as the name implies! Scam is a prototyping tool intended for designing REST APIs and supporting frontend development.

Scam is still quite early in development.

Usage

npm install express scam --save
const path = require('path')
const express = require('express')
const scam = require('scam')
const app = express()
app.set('port', (process.env.PORT || 3333))

scam.init(app, {
  data: { ... },
  schema: { ... },
  databasePath: path.resolve(__dirname, './db.sql')
})

app.listen(app.get('port'), function () {
  scam.log()
})

See the demo project for a better example.

Schema

{
  posts: {
    singular: 'post',
    plural: 'posts',
    fields: [
      name: {
        type: 'string'
      },
      body: {
        type: 'string'
      },
      flagged: {
        type: 'boolean',
        default: false
      },
      user: {
        type: 'user' // Note singular
      },
      comments: {
        type: 'comments' // Note plural
      }
    ]
  },
  comments: {
    ...
  },
  users: {
    ...
  }
}

Data (optional)

{
  posts: [
    {
      name: 'Some Name',
      body: 'Body text body text body text',
      user: 1,
      comments: [1, 2, 3]
    },

    ...

  ]
}

Options

{
  // Set Scam to debug mode (prints internal error messages on 500)
  debug: debug,

  // Default cache time (can be overwritten per resource in schema)
  cache: 0,

  // Dummy data as an object, or path to `require` it from
  data: require('./data'),

  // API schema as an object, or path to `require` it from
  schema: require('./schema'),

  // Path of the db file to create/remove/update (in-memory DB not yet supported)
  databasePath: path.resolve(__dirname, 'db/db.sql')
}

API

let app = require('express')()
let scam = require('scam')

// Prepare a new Scam instance
scam.init(app, options)

// Delete DB if it exists
scam.clearDatabase()

// Init new DB based on schema
scam.setupDatabase()

// Load dummy data
scam.loadData()

// Print instructions and endpoints
scam.log()

// Access props
scam.data
scam.dbPath
scam.endpoints
scam.schema

Deployment

You can deploy a Scam API just like any other express app. A quick way to try it out is to host your repo on GitHub and connect it to Heroku.

Schema: Field types

The following raw types are supported:

  • (integer)
  • string
  • float
  • boolean
  • array (will be stored as string (of JSON) in DB)
  • date
  • time
  • timestamp

Default is 'integer', and it doesn't need to be specified.

You can also use the key of another resource type as the type. In this case the values are integers and are treated as IDs pointing to resources of the given type.

Contributing

Scam is still early in development, and pretty hacky. See todo.md for the next steps.

Feel free to file issues or PRs though!