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

@rockerjs/rpc

v1.0.2

Published

RPC for Rockerjs, including Dubbo and HTTP client

Downloads

6

Readme

业务方定义接口

Http接口定义可用装饰器

  • Resource

业务方在任意位置定义需要使用到的接口,依赖 @vdian/rpc 包提供的 Resource、Resource 装饰器。 Resource唯一参数为用户自定义选项(object),具体可查看 request 官方文档中的参数 https://github.com/request/request#requestoptions-callback。 例:

import { Resource } from '@vdian/rpc';

export abstract class HttpRequest {
    @Resource({ url: '/promotion/item.auctionForWinner/1.0' })
    auctionForWinner(activityId: number, itemId: number, bizType: string): any {}
}


// 目前 thor 的传参结构是 param: JSON.stringify({你的参数})。
// 中间件在这里做了一层封装,因此业务方定义的参数实际上是在 param 中需要传递的参数。
// 仔细检查,切勿写错参数名。

Dubbo接口定义可用装饰器

  • Resource
  • Param 所有参数必须调用 Param 传递类型!
Resource 装饰器的用法
import { Resource } from '@vdian/rpc';
// Resource 定义服务端类目、version(默认 1.0.0)
@Resource({service: 'com.vdian.DemoService', version: '1.0.0'})
export class DubboTest {
    getName() {}
}
Param 装饰器定义
type paramDefined = {
    type?: string,
    key?: {
        [propName: string]: paramDefined
    } | string,
    detail?: {
        [propName: string]: paramDefined
    } | string
} | string
Param 装饰器的几种用法
注:List内的Long类型必须定义,js整型默认会被转化为int
  • 参数为基本类型
import { Resource, Param } from '@vdian/rpc';
@Resource({service: 'com.vdian.DemoService', version: '1.0.0'})
export class DubboTest {
  getNameById(@Param("Long") id: number) {}
}
  • 参数为封装类型时
import { Resource, Param } from '@vdian/rpc';

type demoParamInTs = {
  userId: number,
  id: number,
  type: string
}

@Resource({service: 'com.vdian.DemoService', version: '1.0.0'})
export class DubboTest {
  getNameByDetail(@Param('com.vdian.demoParam') param: demoParamInTs){}
}
  • 参数为 List,内部为 Long、封装类
import { Resource, Param } from '@vdian/rpc';
@Resource({service: 'com.vdian.DemoService', version: '1.0.0'})
export class DubboTest {
  getNamesByIds(@Param({type: "List", detail: "Long"}) param: Array<number>){}

  getNamesByIds(@Param({type: "List", detail: "com.vdian.demoParamInner"}) param: any){}
}
  • 参数为嵌套封装类
import { Resource, Param } from '@vdian/rpc';
@Resource({service: 'com.vdian.DemoService', version: '1.0.0'})
export class DubboTest {
  getNamesByIds(@Param({
     type: "com.vdian.demoParam", 
     detail: {
       innerParam: "com.vdian.demoParamInner"
	 }
  }) param: Array<number>){}
}
  • 参数为List,内部为嵌套封装类。使用 * 标记 List 内所有字段
import { Resource, Param } from '@vdian/rpc';
@Resource({service: 'com.vdian.DemoService', version: '1.0.0'})
export class DubboTest {
   getNamesByIds(@Param({type: "List", detail: {
     "*": {
        type: "com.vdian.demoParamInner"
        detail: {
           id: "Long"
		}
	}
  }}) param: any){}
}
  • 参数为 HashMap, 键需指定类型
import { Resource, Param } from '@vdian/rpc';
@Resource({service: 'com.vdian.DemoService', version: '1.0.0'})
export class DubboTest {
	beanHashMap(@Param({
        type: "HashMap", 
        key:  "com.vdian.DemoParamKey"
    }) customerObj: any) {}
}

初始化配置

Rpc.config(dubboConfig, httpConfig?, trace?)

  • dubboConfig

查询服务信息 http://admin.dubbo.daily.vdian.net/governance/services#

type dubboConfig = {
  application: {name: "当前应用名"},
  dubboVer: "调用远程服务器上的 dubbo 版本"
  dependencies: ["业务方定义的接口"]
  env: "daily | pre | prod  默认 daily"
}
  • httpConfig
type {
    interface: Function | Array<Function> | Array<{service: Function, baseUrl?: string}>,
    baseUrl?: string
}
例:
import { DubboTest } from './interface/dubboInterface';
import { HttpRequest } from './interface/httpInterface';

Rpc.config({
    application: {name: 'testServices'},
    dubboVer: '3.0.4',
    dependencies: [DubboTest],
    env: 'daily'
}, {
    baseUrl: 'https://thor.weidian.com',
    interface: HttpRequest,
})

调用 API

import { Get, Param, Request } from '@vdian/rocker-mvc';
import { Inject} from '@vdian/rocker';
import { DubboTest } from './interface/dubboInterface';

export default class Biz{
    @Inject
    private dubboTest: DubboTest

    @Get({ url: '/dubbo', render: './template/index.vue' })
    async get(@Request _ctx) {
        const customerObj = {
            userId: "123456",
            appId: "wdbuyer",
            pubType: 1,
            weexSDKVersion: "5.1.0"
        };
        const res = await this.dubboTest.getWeexUrl(customerObj)
    }
}