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

open-rest-helper-rest

v2.2.0

Published

open-rest 的 helper 插件,用来实现 CRUD 的标准操作

Downloads

43

Readme

open-rest-helper-rest

open-rest 的 helper 插件,用来实现 CRUD 的标准操作

Build status codecov

Node version

Usage

npm instsall open-rest-helper-rest --save
const rest = require('open-rest');
const restHelper = require('open-rest-helper-rest');

rest.plugin(restHelper);

// restHelper Equivalent to rest.helper.rest

restHelper.list

标准的列表方法

// Model 必选 Sequelize 定义的 Model, 表明要从哪个表获取数据
// opt 可选 特殊的 Model.findAll(options) options 的 hook 名称
// allowAttrs 可选,数组类型,指定允许返回的列,不指定则返回全部
// hook 可选,直接输出或者暂时寄存在 hooks 上

restHelper.list(Model, opt, allowAttrs, hook);

// return
// function(req, res, next) { ... };

//or 链式调用
restHelper
  .list
  .Model(User)
  .exec();

restHelper.detail

标准的输出详情方法

// hook 必选,要输出的数据在 req.hooks 的什么位置
// attachs 可选,要附加输出的数据格式为 key => value, value 是 req 上的路径字符串
// statusCode 可选,输出使用的http状态码, 默认值 200
// attrFilter 可选, 是否允许过滤属性, 默认 true

restHelper.detail(hook, attachs, statusCode, attrFilter);

// return
// function(req, res, next) { ... };

//or 链式调用
restHelper
  .detail
  .hook('user')
  .statusCode(201)
  .attachs({address: 'hooks.address'})
  .exec();

restHelper.remove

标准删除资源的方法

// hook 必选,要删除的实例在 req.hooks 的什么位置

restHelper.remove(hook);

// return
// function(req, res, next) { ... };

//or 链式调用
restHelper
  .remove
  .hook('user')
  .exec();

restHelper.beforeModify

修改资源的前期准备,不包括save到数据库的操作

// Model 必选, Sequlize 定义的Model,表明数据的原型
// hook 必选, 实例的存放位置
// cols 可选, 允许修改的字段

restHelper.beforeModify(Model, hook, cols);

// return
// function(req, res, next) { ... };

//or 链式调用
restHelper
  .beforeModify
  .Model(User)
  .cols(cols)
  .hook('user')
  .exec();

restHelper.save

修改save到数据库的操作

// 修改某个资源描述的后置方法, 将变化保存到数据库
// Model 必选, Sequlize 定义的Model,表明数据的原型
// hook 必选, 实例的存放位置

restHelper.save(hook);

// return
// function(req, res, next) { ... };

//or 链式调用
restHelper
  .save
  .hook('user')
  .exec();

restHelper.modify

标准的修改某个资源的操作

// Model 必选, Sequlize 定义的Model,表明数据的原型
// hook 必选, 实例的存放位置
// cols 可选, 允许修改的字段

restHelper.modify(Model, hook, cols);

// return
// function(req, res, next) { ... };

//or 链式调用
restHelper
  .modify
  .Model(User)
  .cols(cols)
  .hook('user')
  .exec();

restHelper.beforeAdd

创建资源的操作,不包括 res.send 返回

// Model 必选, Sequlize 定义的Model,表明数据的原型
// cols 可选, 允许设置的字段
// hook 必选, 生成实例的存放位置

restHelper.beforeAdd(Model, cols, hook);

// return
// function(req, res, next) { ... };

//or 链式调用
restHelper
  .beforeAdd
  .Model(User)
  .cols(['name', 'age', 'gender'])
  .hook('user')
  .exec();

restHelper.add

标准的创建资源方法

// Model 必选, Sequlize 定义的Model,表明数据的原型
// cols 可选, 允许设置的字段
// hook 可选, 生成实例的存放位置
// attachs 可选,要附加输出的数据格式为 key => value, value 是 req 上的路径字符串

restHelper.add(Model, cols, hook, attachs);

// return
// function(req, res, next) { ... };

//or 链式调用
restHelper
  .add
  .Model(User)
  .cols(['name', 'age', 'gender'])
  .hook('user')
  .exec();

restHelper.batchAdd

批量创建资源方法

// Model 必选, Sequlize 定义的Model,表明数据的原型
// cols 可选, 允许设置的字段
// hook 可选, 生成实例的存放位置
// attachs 可选,要附加输出的数据格式为 key => value, value 是 req 上的路径字符串

restHelper.batchAdd(Model, cols, hook, attachs);

// return
// function(req, res, next) { ... };

//or 链式调用
restHelper
  .batchAdd
  .Model(User)
  .cols(['name', 'age', 'gender'])
  .hook('user')
  .exec();

restHelper.statistics

标准的资源统计功能方法

// Model 必选,Sequlize 定义的Model,表明数据从哪里获取
// where 可选,额外的条件, req 对象上的路径,例如 'hooks.option.where',
// hook 可选, 默认为空,如果指定了hook,则数据不直接输出而是先挂在 hook上
// conf 可选,统计功能的配置,req 对象上值的路径例如 'hooks.user.conf'

restHelper.statistics(Model, 'hooks.opt.where', 'report', 'hooks.conf');

// return
// function(req, res, next) { ... };

//or 链式调用
restHelper
  .statistics
  .Model(User)
  .where('hooks.options.where')
  .conf('hooks.stats.conf')
  .hook('data')
  .exec();