New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

razorframe

Package Overview
Dependencies
Maintainers
2
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

razorframe - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

lib/LinkedList.js

126

lib/Razorframe.js

@@ -1,4 +0,14 @@

const { EventEmitter } = require('events');
const { EventEmitter } = require('events');
const LinkedList = require('./LinkedList');
const express = require('express');
const cluster = require('cluster');
const redis = require('redis');
// const socket = require('socket.io');
const redisAdapter = require('socket.io-redis');
const sticky = require('sticky-session');
const num_workers = require('os').cpus().length || 1;
const app = express();
/**
/**Razorframe constructor
*
* MSG parameters

@@ -9,7 +19,5 @@ * @param {string} MSG.contents => the message value

*/
class Razorframe {
constructor() {
this.storage = {};
this.length = 0;
this.storage = new LinkedList();
this.notification = new EventEmitter();

@@ -19,48 +27,92 @@ }

enqueue(MSG) {
console.log('enqueue has run');
if (!MSG) console.error('Error: must pass in valid msg object!');
if (!MSG.contents) console.error('Error: contents should not be null');
if (!MSG.eventOut) console.error("Error: MSG object must contain valid outbound event name");
else if (!MSG.contents) console.error('Error: contents should not be null');
else if (!MSG.eventOut) console.error("Error: MSG object must contain valid outbound event name");
this.storage[this.length] = MSG;
this.length++;
this.dequeue(); // maybe need to throttle each enq : dq call
else {
this.storage.push(MSG);
this.notification.emit('enq', this.storage.length);
}
}
dequeue() {
if (!this.length) console.error('Error: message queue is currently empty!');
let MSG = this.storage[0];
delete this.storage[0];
for (let i in this.storage) {
this.storage[i - 1] = this.storage[i];
console.log('dequeue has run.');
if (this.storage.length === 0) console.error('Error: message queue is currently empty!');
else {
let MSG = this.storage.pop();
this.notification.emit('deq', MSG);
}
this.length--;
}
}
this.notification.emit('deq', MSG);
let io;
// const { write } = this.NEURON;
// write(MSG.contents);
// this.broadcastOthers(MSG);
// this.broadcastAll(MSG);
}
const rz = {
razorframe: new Razorframe(),
broadcastOthers(MSG) {
const { socket, contents, eventOut } = MSG;
socket.broadcast.emit(eventOut, contents);
}
init(http, config) {
io = require('socket.io')(http);
broadcastAll(MSG) {
const { io, contents, eventOut } = MSG;
io.emit(eventOut, contents);
if (!sticky.listen(http, config.port)) {
// Master code
http.once('listening', function () {
console.log('server started on 3000 port');
});
} else {
// Worker code
handleSockets(config);
}
},
// If errors occur during database writes, the message will be sent to onError function. If it is the first time the message has caused an error, it will be reentered into the queue for a second attempt at a database write, but it will have an error flag. If the same message comes back, it will emit an error message to the client.
onError(MSG) {
if (MSG.error) {
console.log('inside error function with msg:', MSG.contents);
io.to(MSG.id).emit('error', `There was an error writing "${MSG.contents}" to the database.`);
} else {
MSG.error = true;
this.razorframe.enqueue(MSG);
}
}
serverOn(event, data) { }
enqueueAsyncBatch(MSG) { }
dequeueAsyncBatch() { }
}
module.exports = Razorframe;
const handleSockets = (config) => {
const { write, show } = config;
io.on('connection', (socket) => {
console.log('a user connected! 💃');
show(socket);
socket.on('disconnect', () => console.log('user disconnected!'));
// Client listeners
socket.on('msgSent', (MSG, id) => {
MSG.id = socket.id;
rz.razorframe.enqueue(MSG);
});
});
// Server-side listeners
rz.razorframe.notification.on('enq', (data) => {
rz.razorframe.dequeue();
});
rz.razorframe.notification.on('deq', (MSG) => {
write(MSG);
if (!MSG.error) io.emit(MSG.eventOut, MSG.contents);
// Potential way to broadcast error message to client who is source of error
// io.to(MSG.id).emit(MSG.eventOut, MSG.contents);
});
};
module.exports = { Razorframe, rz };
/**

@@ -67,0 +119,0 @@ * Messaging queue module for razorframe.

{
"name": "razorframe",
"version": "1.0.2",
"description": "A real-time database streaming library.",
"main": "./lib/Razorbrain.js",
"version": "1.0.3",
"description": "Empowering real-time databases in Node.js",
"main": "./lib/Razorframe.js",
"scripts": {

@@ -27,4 +27,9 @@ "test": "echo \"Error: no test specified\" && exit 1"

"dependencies": {
"socket.io": "^1.6.0"
"express": "^4.14.0",
"parse-redis-url": "0.0.2",
"redis": "^2.6.3",
"socket.io": "^1.6.0",
"socket.io-redis": "^2.0.1",
"sticky-session": "^1.1.2"
}
}

@@ -1,3 +0,5 @@

# razorframe<sup>(beta)</sup>
####*Empowering real-time databases in Node.js*
# razorframe<sup>(beta)</sup> [![npm version](https://badge.fury.io/js/razorframe.svg)](https://badge.fury.io/js/razorframe)
####*Empowering real-time databases in Node.js*
____________________________________________________________________

@@ -26,3 +28,3 @@

/**
* NEURON parameters - passes into rb any user-defined callbacks
* config parameters - passes into rb any user-defined callbacks
* @param - {Object} http => instantiate an http server

@@ -32,3 +34,3 @@ * @param - {Function} write => a DB write callback (user-defined)

*/
const NEURON = {
const config = {
write: addToDb,

@@ -40,6 +42,6 @@ show: showAll,

* Instantiate razorframe passing in Node's http object
* (to connect with your server) as well as the Neuron object
* (to connect with your server) as well as the config object
* which contains all the user-defined callbacks
*/
rz(http, NEURON);
rz(http, config);
```

@@ -89,7 +91,7 @@

###Support
Tested in Chrome 55 & Node 6.
Tested in Chrome 55 & Node 6/7.
GitHub Issues: <https://github.com/team-emt/razorframe/issues>
###Contributions
❤️Contributions welcome!
❤️ Contributions welcome!
Please see out GitHub repo at: <https://github.com/team-emt/razorframe>

@@ -96,0 +98,0 @@

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