Socket
Socket
Sign inDemoInstall

@akiroz/pubsub-rpc

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@akiroz/pubsub-rpc - npm Package Compare versions

Comparing version 0.0.9 to 0.0.10

10

dist/main.d.ts

@@ -13,5 +13,5 @@ export declare type RPCRequest = {

};
export declare type PubSubClient = {
export declare type PubSubClient<C> = {
publish(topic: string, payload: Uint8Array): Promise<void>;
subscribe(topic: string, handler: (payload: Uint8Array, topic: string) => Promise<void>): Promise<void>;
subscribe(topic: string, handler: (payload: Uint8Array, topic: string, ctx?: C) => Promise<void>): Promise<void>;
unsubscribe(topic: string): Promise<void>;

@@ -22,4 +22,4 @@ };

};
export declare type RPCHandler<P extends RPCParamResult, R extends RPCParamResult> = (param: P, topic: string) => Promise<R | void>;
export declare function register<P extends RPCParamResult, R extends RPCParamResult>(client: PubSubClient, topic: string, handler: RPCHandler<P, R>): Promise<void>;
export declare type RPCHandler<P extends RPCParamResult, R extends RPCParamResult, C> = (param: P, topic: string, ctx?: C) => Promise<R | void>;
export declare function register<P extends RPCParamResult, R extends RPCParamResult, C>(client: PubSubClient<C>, topic: string, handler: RPCHandler<P, R, C>): Promise<void>;
export declare const defaultCallOptions: {

@@ -29,2 +29,2 @@ timeout: number;

};
export declare function call<P extends RPCParamResult, R extends RPCParamResult>(client: PubSubClient, topic: string, params?: P, opt?: Partial<typeof defaultCallOptions>): Promise<R>;
export declare function call<P extends RPCParamResult, R extends RPCParamResult>(client: PubSubClient<void>, topic: string, params?: P, opt?: Partial<typeof defaultCallOptions>): Promise<R>;
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -38,9 +57,2 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }

};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -50,2 +62,3 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

exports.__esModule = true;
exports.call = exports.defaultCallOptions = exports.register = void 0;
var events_1 = require("events");

@@ -61,3 +74,3 @@ var MsgPack = __importStar(require("@msgpack/msgpack"));

switch (_a.label) {
case 0: return [4 /*yield*/, client.subscribe(topic, function (payload, msgTopic) { return __awaiter(_this, void 0, void 0, function () {
case 0: return [4 /*yield*/, client.subscribe(topic, function (payload, msgTopic, ctx) { return __awaiter(_this, void 0, void 0, function () {
var msg, id, params, strId, response;

@@ -79,3 +92,3 @@ return __generator(this, function (_a) {

idDedup.put(strId);
return [4 /*yield*/, handler(params, msgTopic)
return [4 /*yield*/, handler(params, msgTopic, ctx)
.then(function (r) { return ({ result: r || {} }); })["catch"](function (error) { return ({ error: error }); })];

@@ -82,0 +95,0 @@ case 1:

@@ -23,2 +23,3 @@ "use strict";

exports.__esModule = true;
exports.generateCallId = exports.encodeBase64URL = void 0;
function encodeBase64URL(data) {

@@ -25,0 +26,0 @@ var base64 = Buffer

{
"name": "@akiroz/pubsub-rpc",
"version": "0.0.9",
"version": "0.0.10",
"main": "dist/main.js",

@@ -12,16 +12,16 @@ "types": "dist/main.d.ts",

"dependencies": {
"@msgpack/msgpack": "^1.12.1",
"events": "^3.1.0"
"@msgpack/msgpack": "^2.3.0",
"events": "^3.2.0"
},
"devDependencies": {
"@types/mocha": "^7.0.2",
"@types/node": "^13.9.1",
"@types/mocha": "^8.2.0",
"@types/node": "^14.14.14",
"eventemitter2": "^6.4.3",
"husky": "^4.2.3",
"mocha": "^7.1.1",
"husky": "^4.3.6",
"mocha": "^8.2.1",
"parcel-bundler": "^1.12.4",
"prettier": "^2.0.5",
"pretty-quick": "^2.0.1",
"ts-mocha": "^7.0.0",
"typescript": "^3.8.3"
"prettier": "^2.2.1",
"pretty-quick": "^3.1.0",
"ts-mocha": "^8.0.0",
"typescript": "^4.1.3"
},

@@ -28,0 +28,0 @@ "prettier": {

@@ -10,5 +10,5 @@ import { EventEmitter } from "events";

export type PubSubClient = {
export type PubSubClient<C> = {
publish(topic: string, payload: Uint8Array): Promise<void>;
subscribe(topic: string, handler: (payload: Uint8Array, topic: string) => Promise<void>): Promise<void>;
subscribe(topic: string, handler: (payload: Uint8Array, topic: string, ctx?: C) => Promise<void>): Promise<void>;
unsubscribe(topic: string): Promise<void>;

@@ -19,5 +19,6 @@ };

export type RPCHandler<P extends RPCParamResult, R extends RPCParamResult> = (
export type RPCHandler<P extends RPCParamResult, R extends RPCParamResult, C> = (
param: P,
topic: string
topic: string,
ctx?: C
) => Promise<R | void>;

@@ -27,8 +28,8 @@

export async function register<P extends RPCParamResult, R extends RPCParamResult>(
client: PubSubClient,
export async function register<P extends RPCParamResult, R extends RPCParamResult, C>(
client: PubSubClient<C>,
topic: string,
handler: RPCHandler<P, R>
handler: RPCHandler<P, R, C>
) {
await client.subscribe(topic, async (payload, msgTopic) => {
await client.subscribe(topic, async (payload, msgTopic, ctx) => {
if (!(payload instanceof Uint8Array)) throw Error(`Invalid payload: ${payload}`);

@@ -42,3 +43,3 @@ const msg = MsgPack.decode(payload) as RPCRequest;

idDedup.put(strId);
const response = await handler(params, msgTopic)
const response = await handler(params, msgTopic, ctx)
.then((r) => ({ result: r || {} }))

@@ -56,3 +57,3 @@ .catch((error) => ({ error }));

export async function call<P extends RPCParamResult, R extends RPCParamResult>(
client: PubSubClient,
client: PubSubClient<void>,
topic: string,

@@ -59,0 +60,0 @@ params: P = {} as P,

Sorry, the diff of this file is not supported yet

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