Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@creamery/socket.io-rpc

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@creamery/socket.io-rpc - npm Package Compare versions

Comparing version 1.0.5 to 1.0.6

3

lib/common.d.ts

@@ -25,5 +25,6 @@ /// <reference types="socket.io-client" />

export interface ResponseError {
code: number;
code?: number;
name?: string;
message: string;
data?: any;
}
import SocketIO from 'socket.io';
import { Vendor } from './common';
export declare function NotFoundResponse(id: string): {
export declare function NotFoundResponse(id: string, method: string): {
id: string;
method: string;
error: {

@@ -10,11 +11,14 @@ code: number;

};
export declare function ErrorResponse(id: string, err: Error): {
export declare function ErrorResponse(id: string, method: string, err: Error): {
id: string;
method: string;
error: {
code: number;
code: any;
name: string;
message: string;
};
};
export declare function SuccessResponse(id: string, result: any): {
export declare function SuccessResponse(id: string, method: string, result: any): {
id: string;
method: string;
result: any;

@@ -21,0 +25,0 @@ };

@@ -7,5 +7,6 @@ "use strict";

const socket_io_1 = __importDefault(require("socket.io"));
function NotFoundResponse(id) {
function NotFoundResponse(id, method) {
return {
id,
method,
error: {

@@ -18,7 +19,9 @@ code: -32601,

exports.NotFoundResponse = NotFoundResponse;
function ErrorResponse(id, err) {
function ErrorResponse(id, method, err) {
return {
id,
method,
error: {
code: 1,
code: err.code || -32000,
name: err.name,
message: err.message,

@@ -29,5 +32,6 @@ },

exports.ErrorResponse = ErrorResponse;
function SuccessResponse(id, result) {
function SuccessResponse(id, method, result) {
return {
id,
method,
result,

@@ -86,12 +90,16 @@ };

if (typeof vendor[method] === 'function') {
vendor[method](...params)
.then((result) => {
callback(SuccessResponse(id, result));
})
.catch((err) => {
callback(ErrorResponse(id, err));
});
const p = vendor[method](...params);
if (typeof p.then === 'function' && typeof p.catch === 'function') {
p.then((result) => {
callback(SuccessResponse(id, method, result));
}).catch((err) => {
callback(ErrorResponse(id, method, err));
});
}
else {
callback(ErrorResponse(id, method, new Error(`faild: the method must return a promise.`)));
}
return;
}
callback(NotFoundResponse(id));
callback(NotFoundResponse(id, method));
}

@@ -98,0 +106,0 @@ }

{
"name": "@creamery/socket.io-rpc",
"version": "1.0.5",
"version": "1.0.6",
"description": "RPC for SocketIO",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

# socket-io-rpc
RPC for SocketIO
send 427
receive 437
基于 SocketIO 编写的 RPC 框架,主要功能是提供类似本地函数调用的编码体验。

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc