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

asrpc

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

asrpc - npm Package Compare versions

Comparing version 1.0.3 to 1.0.5

19

dist/index.js

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

const isSocketResetError = require("is-socket-reset-error");
const bsp_1 = require("bsp");
const util_1 = require("./util");

@@ -18,2 +19,3 @@ var oid = 0;

this.queue = [];
this.remains = [];
}

@@ -53,4 +55,6 @@ register(target) {

}).on("connection", socket => {
let remains = [];
socket.on("data", buf => {
for (let [event, ...data] of util_1.receive(buf)) {
let msg = bsp_1.receive(buf, remains);
for (let [event, ...data] of msg) {
event = isNaN(event) ? event : util_1.RPCEvents[event];

@@ -66,7 +70,7 @@ socket.emit(event, ...data);

this.instances[oid] = new this.services[id](...args);
socket.write(util_1.send(util_1.RPCEvents.CONNECTED, oid, id));
socket.write(bsp_1.send(util_1.RPCEvents.CONNECTED, oid, id));
}
else {
let err = new Error(`service '${name}' not registered`);
socket.write(util_1.send(util_1.RPCEvents.CONNECT_ERROR, oid, err));
socket.write(bsp_1.send(util_1.RPCEvents.CONNECT_ERROR, oid, err));
}

@@ -78,6 +82,6 @@ }).on(util_1.RPCEvents[3], (oid) => {

let service = this.instances[oid], res = yield service[method](...args);
yield new Promise(resolve => socket.write(util_1.send(util_1.RPCEvents.RESPONSE, oid, taskId, res), () => resolve()));
yield new Promise(resolve => socket.write(bsp_1.send(util_1.RPCEvents.RESPONSE, oid, taskId, res), () => resolve()));
}
catch (err) {
socket.write(util_1.send(util_1.RPCEvents.ERROR, oid, taskId, err));
socket.write(bsp_1.send(util_1.RPCEvents.ERROR, oid, taskId, err));
}

@@ -141,3 +145,4 @@ }));

}).on("data", buf => {
for (let [event, oid, ...data] of util_1.receive(buf)) {
let msg = bsp_1.receive(buf, this.remains);
for (let [event, oid, ...data] of msg) {
event = isNaN(event) ? event : util_1.RPCEvents[event];

@@ -197,3 +202,3 @@ this.instances[oid][util_1.eventEmitter].emit(event, ...data);

}
this.client.write(util_1.send.apply(void 0, msg), cb);
this.client.write(bsp_1.send.apply(void 0, msg), cb);
}

@@ -200,0 +205,0 @@ else {

@@ -6,3 +6,3 @@ "use strict";

const os = require("os");
const encoded_buffer_1 = require("encoded-buffer");
const bsp_1 = require("bsp");
exports.classId = Symbol("classId");

@@ -28,18 +28,2 @@ exports.objectId = Symbol("objectId");

exports.getClassId = getClassId;
function send(event, id, ...data) {
return Buffer.concat([
encoded_buffer_1.encode([event, id, ...data]),
Buffer.from("\r\n\r\n")
]);
}
exports.send = send;
function receive(buf) {
let pack = splitBuffer(buf, "\r\n\r\n"), parts = [];
for (let part of pack) {
if (part)
parts.push(encoded_buffer_1.decode(part)[0]);
}
return parts;
}
exports.receive = receive;
function proxify(srv, oid, ins) {

@@ -59,3 +43,3 @@ return new Proxy(srv, {

}, ins.timeout);
ins["client"].write(send(RPCEvents.REQUEST, oid, taskId, prop, ...args));
ins["client"].write(bsp_1.send(RPCEvents.REQUEST, oid, taskId, prop, ...args));
exports.tasks[taskId] = {

@@ -104,10 +88,2 @@ resolve: (res) => {

exports.absPath = absPath;
function splitBuffer(buf, sep) {
let parts = [], offset = 0, index = -1;
while (0 <= (index = buf.indexOf(sep, offset))) {
parts.push(buf.slice(offset, index));
offset = index + sep.length;
}
return parts;
}
function set(target, prop, value, writable = false) {

@@ -114,0 +90,0 @@ Object.defineProperty(target, prop, {

{
"name": "asrpc",
"version": "1.0.3",
"version": "1.0.5",
"description": "A tool to make your class as an RPC service.",

@@ -26,3 +26,3 @@ "main": "dist/index.js",

"@types/fs-extra": "^5.0.4",
"encoded-buffer": "^0.2.1",
"bsp": "^0.1.1",
"fs-extra": "^7.0.0",

@@ -29,0 +29,0 @@ "is-socket-reset-error": "^0.1.1",

@@ -6,6 +6,5 @@ import * as net from "net";

import isSocketResetError = require("is-socket-reset-error");
import { send, receive } from "bsp";
import {
getClassId,
send,
receive,
tasks,

@@ -21,2 +20,4 @@ proxify,

export type ServiceClass<T> = new (...args) => T;
type ServerPackage = [string | number, number, ...any[]];
type ClientPackage = [string | number, ...any[]];

@@ -48,2 +49,3 @@ export interface ServiceOptions {

private queue: any[][] = [];
private remains: Buffer[] = [];

@@ -101,4 +103,6 @@ /**

}).on("connection", socket => {
let remains: Buffer[] = [];
socket.on("data", buf => {
for (let [event, ...data] of receive(buf)) {
let msg = receive<ClientPackage>(buf, remains);
for (let [event, ...data] of msg) {
event = isNaN(<any>event) ? event : RPCEvents[event];

@@ -212,3 +216,4 @@ socket.emit(<string>event, ...data);

}).on("data", buf => {
for (let [event, oid, ...data] of receive(buf)) {
let msg = receive<ServerPackage>(buf, this.remains);
for (let [event, oid, ...data] of msg) {
event = isNaN(<any>event) ? event : RPCEvents[event];

@@ -215,0 +220,0 @@ this.instances[oid][eventEmitter].emit(event, ...data);

import hash = require("object-hash");
import * as path from "path";
import * as os from "os";
import { encode, decode } from "encoded-buffer";
import { send } from "bsp";
import { ServiceClass, ServiceInstance } from "./index";

@@ -34,20 +34,2 @@

export function send(event: string | number, id: string | number, ...data: any[]) {
return Buffer.concat([
encode([event, id, ...data]),
Buffer.from("\r\n\r\n")
]);
}
export function receive(buf: Buffer): Array<[string | number, string | number, any]> {
let pack = splitBuffer(buf, "\r\n\r\n"),
parts = [];
for (let part of pack) {
if (part) parts.push(decode(part)[0]);
}
return parts;
}
export function proxify(srv: any, oid: number, ins: ServiceInstance): any {

@@ -122,15 +104,2 @@ return new Proxy(srv, {

function splitBuffer(buf: Buffer, sep: string) {
let parts: Buffer[] = [],
offset = 0,
index = -1;
while (0 <= (index = buf.indexOf(sep, offset))) {
parts.push(buf.slice(offset, index));
offset = index + sep.length;
}
return parts;
}
function set(target, prop, value, writable = false) {

@@ -137,0 +106,0 @@ Object.defineProperty(target, prop, {

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