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

@anephenix/sarus

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@anephenix/sarus - npm Package Compare versions

Comparing version 0.4.5 to 0.4.6

2

__tests__/index/connectionOptions.test.ts

@@ -8,3 +8,3 @@ // File Dependencies

const arrayOfProtocols: Array<string> = ["hybi-07", "hybi-00"];
const binaryTypes: Array<string> = ["blob", "arraybuffer"];
const binaryTypes: Array<BinaryType> = ["blob", "arraybuffer"];

@@ -11,0 +11,0 @@ describe("connection options", () => {

# CHANGELOG
### 0.4.6 - Sunday 18th June, 2023
- Remove string typing on messages sent via WebSocket, to align with TypeScript any type
- Updated dependencies
### 0.4.5 - Sunday 18th June, 2023

@@ -4,0 +9,0 @@

@@ -1,7 +0,7 @@

import { EventListenersInterface } from "./lib/validators";
import { PartialEventListenersInterface, EventListenersInterface } from "./lib/validators";
export interface SarusClassParams {
url: string;
binaryType?: string;
binaryType?: BinaryType;
protocols?: string | Array<string>;
eventListeners?: EventListenersInterface;
eventListeners?: PartialEventListenersInterface;
retryProcessTimePeriod?: number;

@@ -30,3 +30,3 @@ reconnectAutomatically?: boolean;

url: string;
binaryType?: string;
binaryType?: BinaryType;
protocols?: string | Array<string>;

@@ -79,3 +79,3 @@ eventListeners: EventListenersInterface;

*/
auditEventListeners(eventListeners?: EventListenersInterface): EventListenersInterface;
auditEventListeners(eventListeners: PartialEventListenersInterface): EventListenersInterface;
/**

@@ -132,9 +132,9 @@ * Connects the WebSocket client, and attaches event listeners

*/
send(data: any): void;
send(data: unknown): void;
/**
* Sends a message over the WebSocket, removes the message from the queue,
* and calls proces again if there is another message to process.
* @param {string} data - The data payload to send over the WebSocket
* @param {unknown} data - The data payload to send over the WebSocket
*/
processMessage(data: string): void;
processMessage(data: unknown): void;
/**

@@ -141,0 +141,0 @@ * Processes messages that are on the message queue. Handles looping through the list, as well as retrying message

"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {

@@ -62,4 +73,4 @@ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {

// Extract the properties that are passed to the class
var url = props.url, binaryType = props.binaryType, protocols = props.protocols, eventListeners = props.eventListeners, reconnectAutomatically = props.reconnectAutomatically, retryProcessTimePeriod = props.retryProcessTimePeriod, // TODO - write a test case to check this
retryConnectionDelay = props.retryConnectionDelay, _a = props.storageType, storageType = _a === void 0 ? "memory" : _a, _b = props.storageKey, storageKey = _b === void 0 ? "sarus" : _b;
var url = props.url, binaryType = props.binaryType, protocols = props.protocols, _a = props.eventListeners, eventListeners = _a === void 0 ? constants_1.DEFAULT_EVENT_LISTENERS_OBJECT : _a, reconnectAutomatically = props.reconnectAutomatically, retryProcessTimePeriod = props.retryProcessTimePeriod, // TODO - write a test case to check this
retryConnectionDelay = props.retryConnectionDelay, _b = props.storageType, storageType = _b === void 0 ? "memory" : _b, _c = props.storageKey, storageKey = _c === void 0 ? "sarus" : _c;
this.eventListeners = this.auditEventListeners(eventListeners);

@@ -197,10 +208,10 @@ // Sets the WebSocket server url for the client to connect to.

Sarus.prototype.auditEventListeners = function (eventListeners) {
if (eventListeners === void 0) { eventListeners = {
var defaultEventListeners = {
open: [],
message: [],
error: [],
close: [],
message: [],
error: []
}; }
// validateEvents(eventListeners);
return eventListeners;
};
var mergedEventListeners = __assign(__assign({}, defaultEventListeners), eventListeners); // Type assertion added here
return mergedEventListeners;
};

@@ -229,3 +240,3 @@ /**

else {
self.connect();
self.connect(); // NOTE - this line is not tested
}

@@ -327,3 +338,3 @@ break;

* and calls proces again if there is another message to process.
* @param {string} data - The data payload to send over the WebSocket
* @param {unknown} data - The data payload to send over the WebSocket
*/

@@ -388,6 +399,5 @@ Sarus.prototype.processMessage = function (data) {

Sarus.prototype.setBinaryType = function () {
var self = this;
var binaryType = self.binaryType;
if (binaryType)
self.ws.binaryType = binaryType;
var binaryType = this.binaryType;
if (binaryType && this.ws)
this.ws.binaryType = binaryType;
};

@@ -394,0 +404,0 @@ return Sarus;

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

import { EventListenersInterface } from "./validators";
/**

@@ -13,1 +14,12 @@ * A definitive list of events for a WebSocket client to listen on

export declare const DATA_STORAGE_TYPES: Array<string>;
/**
* Default event listeners object in case none is passed to the class
* @constant
* @type {object}
* @property {array} open - An array of functions to be called when the WebSocket opens
* @property {array} message - An array of functions to be called when the WebSocket receives a message
* @property {array} error - An array of functions to be called when the WebSocket encounters an error
* @property {array} close - An array of functions to be called when the WebSocket closes
* @property {array} [key] - An array of functions to be called when the WebSocket emits an event with the name of the key
*/
export declare const DEFAULT_EVENT_LISTENERS_OBJECT: EventListenersInterface;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DATA_STORAGE_TYPES = exports.WS_EVENT_NAMES = void 0;
exports.DEFAULT_EVENT_LISTENERS_OBJECT = exports.DATA_STORAGE_TYPES = exports.WS_EVENT_NAMES = void 0;
/**

@@ -21,1 +21,17 @@ * A definitive list of events for a WebSocket client to listen on

exports.DATA_STORAGE_TYPES = ["session", "local"];
/**
* Default event listeners object in case none is passed to the class
* @constant
* @type {object}
* @property {array} open - An array of functions to be called when the WebSocket opens
* @property {array} message - An array of functions to be called when the WebSocket receives a message
* @property {array} error - An array of functions to be called when the WebSocket encounters an error
* @property {array} close - An array of functions to be called when the WebSocket closes
* @property {array} [key] - An array of functions to be called when the WebSocket emits an event with the name of the key
*/
exports.DEFAULT_EVENT_LISTENERS_OBJECT = {
open: [],
message: [],
error: [],
close: []
};

@@ -6,3 +6,10 @@ export interface EventListenersInterface {

close: Array<Function>;
[key: string]: Array<Function>;
[key: string]: Function[];
}
export interface PartialEventListenersInterface {
open?: Array<Function>;
message?: Array<Function>;
error?: Array<Function>;
close?: Array<Function>;
[key: string]: Array<Function> | undefined;
}
{
"name": "@anephenix/sarus",
"version": "0.4.5",
"version": "0.4.6",
"description": "A WebSocket JavaScript library",
"main": "dist/index.js",
"devDependencies": {
"@babel/parser": "^7.20.3",
"@babel/types": "^7.20.2",
"@types/jest": "^29.2.3",
"@babel/parser": "^7.22.5",
"@babel/types": "^7.22.5",
"@types/jest": "^29.5.2",
"@types/websocket": "^1.0.5",

@@ -16,8 +16,8 @@ "coveralls": "^3.1.1",

"jest-websocket-mock": "^2.4.0",
"jsdoc": "^4.0.0",
"jsdom": "^22.0.0",
"mock-socket": "^9.1.5",
"jsdoc": "^4.0.2",
"jsdom": "^22.1.0",
"mock-socket": "^9.2.1",
"npm-upgrade": "^3.1.0",
"ts-jest": "^29.0.3",
"typescript": "^5.0.2"
"ts-jest": "^29.1.0",
"typescript": "^5.1.3"
},

@@ -45,4 +45,4 @@ "scripts": {

"@types/window-or-global": "^1.0.4",
"jest-environment-jsdom": "^29.3.1"
"jest-environment-jsdom": "^29.5.0"
}
}

@@ -44,3 +44,3 @@ // File Dependencies

url: string;
binaryType?: string;
binaryType?: BinaryType;
protocols?: string | Array<string>;

@@ -73,3 +73,3 @@ eventListeners?: PartialEventListenersInterface;

url: string;
binaryType?: string;
binaryType?: BinaryType;
protocols?: string | Array<string>;

@@ -386,3 +386,3 @@ eventListeners: EventListenersInterface;

*/
send(data: any) {
send(data: unknown) {
const callProcessAfterwards = this.messages.length === 0;

@@ -396,5 +396,5 @@ this.addMessage(data);

* and calls proces again if there is another message to process.
* @param {string} data - The data payload to send over the WebSocket
* @param {unknown} data - The data payload to send over the WebSocket
*/
processMessage(data: string) {
processMessage(data: unknown) {
const self: any = this;

@@ -458,6 +458,5 @@ self.ws.send(data);

setBinaryType() {
const self: any = this;
const { binaryType } = self;
if (binaryType) self.ws.binaryType = binaryType;
const { binaryType } = this;
if (binaryType && this.ws) this.ws.binaryType = binaryType;
}
}
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