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

core.io-view-generator

v0.10.0

Published

CRUD view generator

Downloads

8

Readme

Generate CRUD views from a (swagerish) model schema. If you are using Waterline, you can generate the schema using the waterline-to-json-schema module.

CLI

   scaffold 0.1.3 - CRUD view generator

   USAGE

     scaffold <command> [options]

   COMMANDS

     compile [source] [output]      Generate views from a GUI schema
     open [source] [output]         Generate views from a JSON schema
     help <command>                 Display help for a specific command

   GLOBAL OPTIONS

     -h, --help         Display help
     -V, --version      Display version
     --no-color         Disable colors
     --quiet            Quiet mode - only displays warn and error messages
     -v, --verbose      Verbose mode - will also output debug messages

For each model create the following views:

  • update: Update
  • create: Create
  • index: Instance
  • list: Table
  • search: Search

With two subviews:

  • _grid
  • _form

Attribute type mapping:

  • string: Input
  • text: TextArea
  • integer: Input
  • float: Input
  • date: Input
  • time: Input
  • datetime: Input
  • boolean: Check
  • binary: Input
  • array: Multi?
  • json: TextArea
//Actual Box
var Box = Waterline.Collection.extend({
    identity: 'box',
    //TODO: change identity name, make
    //as exportName, and remove exportName.
    exportName: 'Box',
    connection: connection,
    attributes: {
        name: {
            type:'string',
            // description: 'Box name'
        },
        uuid: {
            type: 'string',
            required: true,
            defaultsTo: function() {
                return uuid();
            }
        },
        eventName: 'string',
        eventResponse: 'string',
        eventAction: {
            type:'string',
            defaultsTo: 'ACTIVATE'
        },
        boxset: {
            model: 'boxset'
        },
        owner: {
            model: 'boxowner'
        },
        status: {
            type: 'string',
            //Should this be 3 states only?
            //available - assigned - broken? That way we do not
            //have to update on "route"
            enum: [ 'available', 'assigned', 'delivered', 'full', 'broken'],
            defaultsTo: 'available'
        }
    }
});

https://github.com/balderdashy/waterline-docs/blob/master/models/validations.md

{
    attributes: {
      foo: {

          required: true,+

          empty: true,
          notEmpty: true,
          undefined: true,
          falsey: true,
          truthy: true,
          null: true,
          notNull: true,


          after: '12/12/2001',
          before: '12/12/2001',

          equals: 45,


          in: ['foo', 'bar'], // string contains one of this
          notIn: ['foo', 'bar'],// string NOT contains one of this

          contains: 'foobar',+
          notContains: 'foobar',+

          is: /ab+c/,+
          regex: /ab+c/,+
          not: /ab+c/,+
          notRegex: /ab+c/,+

          len: 35,+
          max: 24,+
          min: 4,+
          minLength: 4,+
          maxLength: 24,+

          lowercase: true,+
          uppercase: true,+

          string: true,+
          alpha: true,+
          numeric: true,+
          alphanumeric: true,+
          int: true,+
          integer: true,+
          number: true,+
          finite: true,+
          decimal: true,+
          float: true,+
          boolean: true,+

          array: true,+
          date: true,+
          hexColor: true,+
          hexadecimal: true,+
          email: true,+
          url: true,+
          urlish: true,+
          ip: true,+
          ipv4: true,+
          ipv6: true,+
          creditcard: true,+
          uuid: true,+
          uuidv3: true,+
          uuidv4: true,+
      }
    }
}

Swagger

The generated schema can be used in the definitions part of a Swagger Manifest. If you use Swagger with your API you can extend the definitions with the generated JSON.

{
  type: 'object',
  title: 'User',
  properties: {
    id: {
      type: 'integer',
      format: 'int32'
    },
    title: { type: 'string' },
    description: { type: 'string' },
    createdAt: {
      type: 'string',
      format: 'date-time'
    },
    updatedAt: {
      type: 'string',
      format: 'date-time'
    }
  }
}
{
  "swagger": "2.0",
  "info": {
    "title": "API",
    "version": "1.0.0"
  },
  "paths": {
    "user": {
      "get": {      
        "parameters": [ ],
        "responses": {
          "200": { "$ref": "#/definitions/user" }
        }
      }
    }
  },
  "definitions": {
    "user": {
      "type": "object",
      "properties": {
        "id": {
          "type": "integer",
          "format": 'int32'
        },
        "title": { "type": "string" },
        "description": { "type": "string" },
        "createdAt": {
          "type": "string",
          "format": "date-time"
        },
        "updatedAt": {
          "type": "string",
          "format": "date-time"
        }
      }
    }
  }
}

Inputs

To debug you might want to show what a field metadata contains. You can add the following entry in the __inputs.swig file on a field:

<code>{{ prop|json|safe -}}</code>
{
    "name": "terminals",
    "label": "Terminals",
    "entityType": "array",
    "uri": "/terminal",
    "type": "text",
    "element": "multiselect",
    "items": {
        "$ref": "#/definitions/terminal"
    },
    "subType": "array",
    "relType": "many-to-one"
}

Templates

Field

{
    "name": "parent",
    "label": "Parent",
    "entityType": {
        "$ref": "#/definitions/location"
    },
    "uri": "/location",
    "type": "text",
    "element": "select",
    "relType": "one-to-many"
}

Generate Views

Flow:

  1. waterline-schema collect ./src/models (output: waterline.json)

  2. waterline-schema generate (output: schema.json)

  3. scaffold-views generate schema.json ./output/ --clean --save-gui-schema: Modify gui-schema.json to arrange fields as we want them, i.e move id field to be 1st.

  4. scaffold-views compile gui-schema.json ./output/

Templates

A note on templates... potentially you are using templates to generate templates. The view generator uses the tags {% and %}. If you are mixing ejs, make sure you don't open tags without noticing:

The following would break the cli template parsing:

<% pagination.getPages().forEach((page)=>{%>
    <li class="<%= page.active ? 'active' : ''%>">
        <a href="<%= page.link%>">
            <%= page.index %>
        </a>
    </li>
<%})%>

Notice the forEach((page)=>{%>, yup, that {% it's an opening tag..

Here we fix the issues:

<% pagination.getPages().forEach((page)=> { %> <%# THIS! %>
    <li class="<%= page.active ? 'active' : '' %>">
        <a href="<%= page.link%>">
            <%= page.index %>
        </a>
    </li>
<% }) %><%# THIS! %>