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

modelproxy-promise

v1.0.3

Published

### 说明

Downloads

8

Readme

modelproxy-promise

说明

该模块基于modelproxy改写,由于项目是在node新版本,基于co(Promise+Generator) 解决回调嵌套,所以在原基础上进行了部分改写。

安装


npm install modelproxy-promise

配置、初始化

接口配置、初始化同modelproxy

调用方式

var ModelProxy = require('modelproxy-promise');

// {status}可选,此优先级最高,设置会覆盖配置文件中的值
ModelProxy.init('./interface.json', { status: process.env.NODE_ENV });

var searchModel = ModelProxy.create([
		'Search.getPlayInfo',
		'Search.getAlbumList',
		'Search.getAlbumInfos' 
	]);


//单个使用,同es6源生Promise,每个请求有两个参数param,callback[可选],callback可对当前接口结果集进行重写
searchModel
	.getPlayInfo( {playId: 1}, data => 1 )
	.then(
		data => data//1
	)
	.catch(
		error => console.error(error)
	);
	
//多个并行调用,所有请求都成功,才执行最终结果,同Promise.all
searchModel
	.getPlayInfo( {playId: 1} )
	.getAlbumList( {albumId: 2} )
	.all()
	.then(
		dataArray => dataArray.map(data => data.result);
	)
	.catch(
		error => console.error(error)
	);

//多个并行调用,单个请求失败,不影响执行最终结果
searchModel
	.getPlayInfo( {playId: 1} )
	.getAlbumList( {albumId: 2}, data => new Error('data error') )
	.paral()
	.then(
		dataArray => dataArray.map(data => {
			if(data instanceof Error){
				return null;
			}
			return data.result;
		});
	)
	.catch(
		error => console.error(error)
	);

//多个串行调用,下一个请求参数依赖上一个接口返回的结果,
//第二个请求param要求为function,接收参数上一个接口返回结果和前面所有接口返回的结果集合,如果某个接口失败,调用catch
searchModel
	.getPlayInfo( {playId: 1}, data => data )
	.getAlbumList( playInfo => ({albumId: playInfo.albumId}) )
	.getAlbumInfos( (albumList, arrData) => ({albumId: albumList[0].id, playId: arrData[0].id}) )
	.series()
	.then(
		dataArray => dataArray.map(data => data.result)
	)
	.catch(
		error => console.error(error)
	);