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

@push-rpc/core

Package Overview
Dependencies
Maintainers
1
Versions
62
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@push-rpc/core - npm Package Compare versions

Comparing version 1.0.24 to 1.0.25

2

dist/index.d.ts

@@ -7,2 +7,2 @@ export { Topic, RpcContext, RpcConnectionContext, MessageType, Middleware } from "./rpc";

export { setLogger } from "./logger";
export { dateReviver, composeMiddleware, createMessageId, setCreateMessageId } from "./utils";
export { dateReviver, composeMiddleware, createMessageId, setCreateMessageId, mapTopic, } from "./utils";

@@ -18,1 +18,2 @@ "use strict";

exports.setCreateMessageId = utils_1.setCreateMessageId;
exports.mapTopic = utils_1.mapTopic;

@@ -7,3 +7,3 @@ import { DataConsumer, RemoteTopic, TopicImpl } from "./rpc";

constructor(topicName: string, session: RpcSession);
subscribe<SubscriptionKey = DataConsumer<D>>(consumer: DataConsumer<D>, params?: F, subscriptionKey?: SubscriptionKey): SubscriptionKey;
subscribe<SubscriptionKey = DataConsumer<D>>(consumer: DataConsumer<D>, filter?: F, subscriptionKey?: SubscriptionKey): SubscriptionKey;
unsubscribe(params?: F, subscriptionKey?: any): void;

@@ -10,0 +10,0 @@ private deleteAllSubscriptions;

@@ -35,8 +35,12 @@ "use strict";

}
RemoteTopicImpl.prototype.subscribe = function (consumer, params, subscriptionKey) {
if (params === void 0) { params = {}; }
RemoteTopicImpl.prototype.subscribe = function (consumer, filter, subscriptionKey) {
if (filter === void 0) { filter = {}; }
if (subscriptionKey === void 0) { subscriptionKey = consumer; }
var paramsKey = JSON.stringify(params);
if (filter === null) {
throw new Error("Subscribe with null filter is not supported, use empty object to get all data");
}
var paramsKey = JSON.stringify(filter);
this.consumers[paramsKey] = __spreadArrays((this.consumers[paramsKey] || []), [{ consumer: consumer, subscriptionKey: subscriptionKey }]);
this.session.send(rpc_1.MessageType.Subscribe, utils_1.createMessageId(), this.topicName, params);
// TODO it is not necessary to send subscribe if we already have cached value
this.session.send(rpc_1.MessageType.Subscribe, utils_1.createMessageId(), this.topicName, filter);
if (this.cached[paramsKey] !== undefined) {

@@ -43,0 +47,0 @@ consumer(this.cached[paramsKey]);

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

e_2 = _a.sent();
logger_1.log.error("Unable to call method " + name + " with params " + JSON.stringify(params), e_2);
logger_1.log.error("Unable to call method " + name + " with params " + JSON.stringify(params) + ". ", e_2);
this.sendError(id, e_2);

@@ -315,0 +315,0 @@ return [3 /*break*/, 3];

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

close: function (cb) { return socketServer.close(cb); },
/** These remote are not reconnecting - they should not be saved */
getRemote: function (clientId) {

@@ -178,0 +179,0 @@ if (!sessions[clientId])

@@ -1,2 +0,2 @@

import { MessageType, Middleware } from "./rpc";
import { MessageType, Middleware, RemoteTopic } from "./rpc";
export declare function dateReviver(key: any, val: any): any;

@@ -11,1 +11,2 @@ export declare const ISO8601: RegExp;

export declare function composeMiddleware(...middleware: Middleware[]): Middleware;
export declare function mapTopic<D1, P, D2>(t: RemoteTopic<D1, P>, map: (D1: any) => D2): RemoteTopic<D2, P>;
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __spreadArrays = (this && this.__spreadArrays) || function () {

@@ -101,1 +137,27 @@ for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;

exports.composeMiddleware = composeMiddleware;
function mapTopic(t, map) {
return {
subscribe: function (consumer, params, subscriptionKey) {
return t.subscribe(function (d) {
return consumer(map(d));
}, params, subscriptionKey);
},
unsubscribe: function (params, subscriptionKey) {
return t.unsubscribe(params, subscriptionKey);
},
get: function (params) {
return __awaiter(this, void 0, void 0, function () {
var d;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, t.get(params)];
case 1:
d = _a.sent();
return [2 /*return*/, map(d)];
}
});
});
},
};
}
exports.mapTopic = mapTopic;
{
"name": "@push-rpc/core",
"version": "1.0.24",
"version": "1.0.25",
"main": "dist/index.js",

@@ -5,0 +5,0 @@ "types": "dist/index.d.ts",

@@ -7,2 +7,8 @@ export {Topic, RpcContext, RpcConnectionContext, MessageType, Middleware} from "./rpc"

export {setLogger} from "./logger"
export {dateReviver, composeMiddleware, createMessageId, setCreateMessageId} from "./utils"
export {
dateReviver,
composeMiddleware,
createMessageId,
setCreateMessageId,
mapTopic,
} from "./utils"

@@ -17,10 +17,17 @@ import {DataConsumer, MessageType, Method, RemoteTopic, TopicImpl} from "./rpc"

consumer: DataConsumer<D>,
params: F = {} as any,
filter: F = {} as any,
subscriptionKey: SubscriptionKey = consumer as any
): SubscriptionKey {
const paramsKey = JSON.stringify(params)
if (filter === null) {
throw new Error(
"Subscribe with null filter is not supported, use empty object to get all data"
)
}
const paramsKey = JSON.stringify(filter)
this.consumers[paramsKey] = [...(this.consumers[paramsKey] || []), {consumer, subscriptionKey}]
this.session.send(MessageType.Subscribe, createMessageId(), this.topicName, params)
// TODO it is not necessary to send subscribe if we already have cached value
this.session.send(MessageType.Subscribe, createMessageId(), this.topicName, filter)

@@ -27,0 +34,0 @@ if (this.cached[paramsKey] !== undefined) {

@@ -286,3 +286,3 @@ import {log} from "./logger"

} catch (e) {
log.error(`Unable to call method ${name} with params ${JSON.stringify(params)}`, e)
log.error(`Unable to call method ${name} with params ${JSON.stringify(params)}. `, e)
this.sendError(id, e)

@@ -289,0 +289,0 @@ }

@@ -149,2 +149,4 @@ import * as UUID from "uuid-js"

close: cb => socketServer.close(cb),
/** These remote are not reconnecting - they should not be saved */
getRemote: clientId => {

@@ -151,0 +153,0 @@ if (!sessions[clientId]) throw new Error(`Client ${clientId} is not connected`)

import * as UUID from "uuid-js"
import {MessageType, Middleware} from "./rpc"
import {DataConsumer, MessageType, Middleware, RemoteTopic} from "./rpc"

@@ -97,1 +97,22 @@ export function dateReviver(key, val) {

}
export function mapTopic<D1, P, D2>(t: RemoteTopic<D1, P>, map: (D1) => D2): RemoteTopic<D2, P> {
return {
subscribe(consumer: DataConsumer<D2>, params?: P, subscriptionKey?: any) {
return t.subscribe(
(d: D1) => {
return consumer(map(d))
},
params,
subscriptionKey
)
},
unsubscribe(params?: P, subscriptionKey?: any) {
return t.unsubscribe(params, subscriptionKey)
},
async get(params?: P): Promise<D2> {
const d = await t.get(params)
return map(d)
},
}
}
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