New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

tiny-service

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tiny-service

a tiny api library

latest
npmnpm
Version
0.4.4
Version published
Weekly downloads
9
-25%
Maintainers
1
Weekly downloads
 
Created
Source

tiny-service

a tiny service library for generate service functiions

service usage

const {Service} =require('tiny-Service');

// const model= ...;

const roleService=Service(model);

the shape of roleService is

{

    /**
     * return the model itself
     * @return model
     */
    getModel:function(){ },

    /**
     * create model
     * @param record
     * @return {Promise<model>}
     */
    create:model.create,

    /**
     * remove model
     * @return {Promise<model>}
     */
    remove:function(id){ },

    /**
     * update model
     * @param {Integer} id model id
     * @return {Promise<model>} model 的JSON对象
     */
    update:function(id,record){ },


    /**
     * 根据ID查找
     * @param {Integer} id model id
     * @return {Promise<model>} model 的JSON对象
     */
    findById:function(id){ },


    /**
     * find and count all models by page ,size ,condition
     * @param {Number} page current page
     * @param {Number} size page size
     * @param {*} condition 
     * @return {Promise<{count:Number,rows:[]}>} 
     */
    list:function(page=1,size=10,condition={}){ },

    /**
     * list all recent models by page ,size ,condition, order by createdAt desc .
     * model must have a createAt field
     * @param {Number} page current page
     * @param {Number} size page size
     * @param {*} condition 
     * @return {Promise<{count:Number,rows:[]}>} 
     */
    recent:function(page=1,size=10,condition={}){ },

}

to override the default method of service , just rewrite it:

roleService.list=function(page,size,condition){
    // implement 
};

middleware usage

const {Middleware}=require('tiny-service');

// ... const roleService= ...;
const middleware=Middleware(roleService);


const router=express.Router();
const middleware=Middleware(resourceService);


router.post('/create',bodyParser.json(),middleware.create);


router.post('/remove',bodyParser.json(),middleware.remove);


router.post('/update',bodyParser.json(),middleware.update);


router.post('/list',bodyParser.json(),middleware.list);


router.post('/recent',bodyParser.json(),middleware.recent);


module.exports=router;

Keywords

tiny api

FAQs

Package last updated on 08 Mar 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts