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

sails-hook-deepblueprints

v0.0.3

Published

Sails hook plugin that provide 'DEEP' blueprints

Downloads

5

Readme

sails-hook-deepblueprints is sails hook, provide more than two resources layers route which is provided by blueprints in sails native hook

中文版介绍

Features

  • generate more than two resource layers route like /deep/company/1/team/2/project/3
  • validate association between each layer in route path like: if team id 2 is not belong to company id 1, then will return 400 error

Installation

install in sails project

npm install sails-hook-deepblueprints --save

Usage

  • put config deepBluePrint : true into controller which one you want it have deep blueprint routes

    /**
     * CompanyController
     *
     * @description :: Server-side logic for managing companies
     * @help        :: See http://sailsjs.org/#!/documentation/concepts/Controllers
     */
       
    module.exports = {
      _config : {
        deepBluePrint : true
      }
    };
  • after sails start, there will auto generate deep-blueprints' routes with the prefix in the path: /deep

Example

here is complete sample

here are 4 models below, and they have One-to-many associations of one and the next one.

/**
* Company.js
*/
module.exports = {

  attributes: {
    name : "string",
    team:{
      collection: 'team'
    }
  }
};
/**
* Team.js
*/
module.exports = {

  attributes: {
    name : "string",
    project : {
      collection: 'project'
    }
  }
};
/**
* Project.js
*/

module.exports = {

  attributes: {
    name : "string",
    todolist : {
      collection: 'todolist'
    }
  }
};
/**
* Todolist.js
*/

module.exports = {

  attributes: {
    name : "string"
  }
};

after sails start, there will generate the deep-blueprints routes(these can see in the sails logs when log level is silly):

silly: Binding RESTful deepblueprint/shadow routes for model+controller: company
silly: Binding RESTful association deepblueprint `team` for company
silly: Binding route ::  post /deep/company/:parentid/team/:id? (ACTION: company/_config)
silly: Binding route ::  post /deep/company/:parentid/team/:id? (ACTION: company/_config)
silly: Binding route ::  delete /deep/company/:parentid/team/:id? (ACTION: company/_config)
silly: Binding route ::  delete /deep/company/:parentid/team/:id? (ACTION: company/_config)
silly: Binding route ::  put /deep/company/:parentid/team/:id? (ACTION: company/_config)
silly: Binding route ::  put /deep/company/:parentid/team/:id? (ACTION: company/_config)
silly: Binding route ::  get /deep/company/:parentid/team/:id? (ACTION: company/_config)
silly: Binding route ::  get /deep/company/:parentid/team/:id? (ACTION: company/_config)
silly: Binding RESTful association deepblueprint `project` for team
silly: Binding route ::  post /deep/company/*/team/:parentid/project/:id? (ACTION: company/_config)
silly: Binding route ::  post /deep/company/*/team/:parentid/project/:id? (ACTION: company/_config)
silly: Binding route ::  delete /deep/company/*/team/:parentid/project/:id? (ACTION: company/_config)
silly: Binding route ::  delete /deep/company/*/team/:parentid/project/:id? (ACTION: company/_config)
silly: Binding route ::  put /deep/company/*/team/:parentid/project/:id? (ACTION: company/_config)
silly: Binding route ::  put /deep/company/*/team/:parentid/project/:id? (ACTION: company/_config)
silly: Binding route ::  get /deep/company/*/team/:parentid/project/:id? (ACTION: company/_config)
silly: Binding route ::  get /deep/company/*/team/:parentid/project/:id? (ACTION: company/_config)
silly: Binding RESTful association deepblueprint `todolist` for project
silly: Binding route ::  post /deep/company/*/team/*/project/:parentid/todolist/:id? (ACTION: company/_config)
silly: Binding route ::  post /deep/company/*/team/*/project/:parentid/todolist/:id? (ACTION: company/_config)
silly: Binding route ::  delete /deep/company/*/team/*/project/:parentid/todolist/:id? (ACTION: company/_config)
silly: Binding route ::  delete /deep/company/*/team/*/project/:parentid/todolist/:id? (ACTION: company/_config)
silly: Binding route ::  put /deep/company/*/team/*/project/:parentid/todolist/:id? (ACTION: company/_config)
silly: Binding route ::  put /deep/company/*/team/*/project/:parentid/todolist/:id? (ACTION: company/_config)
silly: Binding route ::  get /deep/company/*/team/*/project/:parentid/todolist/:id? (ACTION: company/_config)
silly: Binding route ::  get /deep/company/*/team/*/project/:parentid/todolist/:id? (ACTION: company/_config)

when the request path match these routes, deep-blueprints will take the data processing job and in it is way, mostly like the blueprints do:

add: post %s/:parentid/%s/:id?
remove: delete %s/:parentid/%s/:id?
update: put %s/:parentid/%s/:id?
populate: get %s/:parentid/%s/:id?

Notice

  • the association attribute name in the model should be EXACTLY same as the associate model's name, like :
/**
* Company.js
*/
module.exports = {

    attributes: {
     name : "string",
     team:{ // team is OK, teams is NOT OK
       collection: 'team'
     }
    }
};
/**
* Team.js
*/
module.exports = {

    attributes: {
     name : "string"
    }
};
  • because deep-blueprints will find the associations and create the route, so avoid circle routes, DON'T DEFINE TWO-WAY associations in two models like:
/**
* Company.js
*/
module.exports = {

  attributes: {
    name : "string",
    team:{
      collection: 'team'
    }
  }
};
/**
* Team.js
*/
module.exports = {

  attributes: {
    name : "string",
    company : {
        model : 'company'
    },
    project : {
      collection: 'project'
    }
  }
};

Test

in deep-blueprints sample, clone repo and run npm test