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

@graffy/server

Package Overview
Dependencies
Maintainers
1
Versions
226
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@graffy/server - npm Package Compare versions

Comparing version 0.14.6-alpha1 to 0.14.6-alpha10

431

httpServer.js

@@ -12,4 +12,2 @@ "use strict";

var _stringify = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/json/stringify"));
var _extends2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/extends"));

@@ -29,280 +27,275 @@

if (!store) throw new Error('server.store_undef');
return (
/*#__PURE__*/
function () {
var _ref = (0, _asyncToGenerator2["default"])(
/*#__PURE__*/
_regenerator["default"].mark(function _callee(req, res) {
var parsed, query, options, keepAlive, stream, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, value, _value3, chunks, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, _value2, chunk, change, _value4;
return /*#__PURE__*/function () {
var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(req, res) {
var parsed, query, options, keepAlive, stream, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, value, _value3, chunks, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, _value2, chunk, change, _value4;
return _regenerator["default"].wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
parsed = _url["default"].parse(req.url, true);
query = parsed.query.q && (0, _common.decodeUrl)(parsed.query.q);
options = parsed.query.opts && JSON.parse(decodeURIComponent(parsed.query.opts));
return _regenerator["default"].wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
parsed = _url["default"].parse(req.url, true);
query = parsed.query.q && (0, _common.decodeUrl)(parsed.query.q);
options = parsed.query.opts && (0, _common.deserialize)(decodeURIComponent(parsed.query.opts));
if (!(req.method === 'GET')) {
_context.next = 67;
break;
}
if (!(req.method === 'GET')) {
_context.next = 67;
break;
}
_context.prev = 4;
_context.prev = 4;
if (!(req.headers['accept'] === 'text/event-stream')) {
_context.next = 53;
break;
if (!(req.headers['accept'] === 'text/event-stream')) {
_context.next = 53;
break;
}
res.setHeader('content-type', 'text/event-stream');
keepAlive = (0, _setInterval2["default"])(function () {
if (req.aborted || res.finished) {
clearInterval(keepAlive);
return;
}
res.setHeader('content-type', 'text/event-stream');
keepAlive = (0, _setInterval2["default"])(function () {
if (req.aborted || res.finished) {
clearInterval(keepAlive);
return;
}
res.write(': \n\n');
}, 29000); // TODO: Resumable subscriptions using timestamp ID.
// const lastId = req.headers['last-event-id'];
res.write(': \n\n');
}, 29000); // TODO: Resumable subscriptions using timestamp ID.
// const lastId = req.headers['last-event-id'];
_context.prev = 8;
stream = store.call('watch', query, (0, _extends2["default"])({}, options, {
raw: true
}));
_iteratorNormalCompletion = true;
_didIteratorError = false;
_context.prev = 12;
_iterator = (0, _asyncIterator2["default"])(stream);
_context.prev = 8;
stream = store.call('watch', query, (0, _extends2["default"])({}, options, {
raw: true
}));
_iteratorNormalCompletion = true;
_didIteratorError = false;
_context.prev = 12;
_iterator = (0, _asyncIterator2["default"])(stream);
case 14:
_context.next = 16;
return _iterator.next();
case 14:
_context.next = 16;
return _iterator.next();
case 16:
_step = _context.sent;
_iteratorNormalCompletion = _step.done;
_context.next = 20;
return _step.value;
case 16:
_step = _context.sent;
_iteratorNormalCompletion = _step.done;
_context.next = 20;
return _step.value;
case 20:
_value = _context.sent;
case 20:
_value = _context.sent;
if (_iteratorNormalCompletion) {
_context.next = 29;
break;
}
if (_iteratorNormalCompletion) {
_context.next = 29;
break;
}
value = _value;
value = _value;
if (!(req.aborted || res.finished)) {
_context.next = 25;
break;
}
if (!(req.aborted || res.finished)) {
_context.next = 25;
break;
}
return _context.abrupt("break", 29);
return _context.abrupt("break", 29);
case 25:
res.write("data: " + (0, _common.serialize)(value) + "\n\n");
case 25:
res.write("data: " + (0, _stringify["default"])(value) + "\n\n");
case 26:
_iteratorNormalCompletion = true;
_context.next = 14;
break;
case 26:
_iteratorNormalCompletion = true;
_context.next = 14;
break;
case 29:
_context.next = 35;
break;
case 29:
_context.next = 35;
case 31:
_context.prev = 31;
_context.t0 = _context["catch"](12);
_didIteratorError = true;
_iteratorError = _context.t0;
case 35:
_context.prev = 35;
_context.prev = 36;
if (!(!_iteratorNormalCompletion && _iterator["return"] != null)) {
_context.next = 40;
break;
}
case 31:
_context.prev = 31;
_context.t0 = _context["catch"](12);
_didIteratorError = true;
_iteratorError = _context.t0;
_context.next = 40;
return _iterator["return"]();
case 35:
_context.prev = 35;
_context.prev = 36;
case 40:
_context.prev = 40;
if (!(!_iteratorNormalCompletion && _iterator["return"] != null)) {
_context.next = 40;
break;
}
if (!_didIteratorError) {
_context.next = 43;
break;
}
_context.next = 40;
return _iterator["return"]();
throw _iteratorError;
case 40:
_context.prev = 40;
case 43:
return _context.finish(40);
if (!_didIteratorError) {
_context.next = 43;
break;
}
case 44:
return _context.finish(35);
throw _iteratorError;
case 45:
_context.next = 50;
break;
case 43:
return _context.finish(40);
case 47:
_context.prev = 47;
_context.t1 = _context["catch"](8);
res.write("event: graffyerror\ndata: " + _context.t1.message + "\n\n");
case 44:
return _context.finish(35);
case 50:
res.end();
_context.next = 58;
break;
case 45:
_context.next = 50;
break;
case 53:
_context.next = 55;
return store.call('read', query, (0, _extends2["default"])({}, options, {
raw: true
}));
case 47:
_context.prev = 47;
_context.t1 = _context["catch"](8);
res.write("event: graffyerror\ndata: " + _context.t1.message + "\n\n");
case 55:
_value3 = _context.sent;
res.writeHead(200);
res.end((0, _common.serialize)(_value3));
case 50:
res.end();
_context.next = 58;
break;
case 58:
_context.next = 65;
break;
case 53:
_context.next = 55;
return store.call('read', query, (0, _extends2["default"])({}, options, {
raw: true
}));
case 60:
_context.prev = 60;
_context.t2 = _context["catch"](4);
res.writeHead(400);
res.end(_context.t2.message + "\n\n");
return _context.abrupt("return");
case 55:
_value3 = _context.sent;
res.writeHead(200);
res.end((0, _stringify["default"])(_value3));
case 65:
_context.next = 120;
break;
case 58:
_context.next = 65;
case 67:
if (!(req.method === 'POST')) {
_context.next = 118;
break;
}
case 60:
_context.prev = 60;
_context.t2 = _context["catch"](4);
res.writeHead(400);
res.end(_context.t2.message + "\n\n");
return _context.abrupt("return");
_context.prev = 68;
chunks = [];
_iteratorNormalCompletion2 = true;
_didIteratorError2 = false;
_context.prev = 72;
_iterator2 = (0, _asyncIterator2["default"])(req);
case 65:
_context.next = 120;
break;
case 74:
_context.next = 76;
return _iterator2.next();
case 67:
if (!(req.method === 'POST')) {
_context.next = 118;
break;
}
case 76:
_step2 = _context.sent;
_iteratorNormalCompletion2 = _step2.done;
_context.next = 80;
return _step2.value;
_context.prev = 68;
chunks = [];
_iteratorNormalCompletion2 = true;
_didIteratorError2 = false;
_context.prev = 72;
_iterator2 = (0, _asyncIterator2["default"])(req);
case 80:
_value2 = _context.sent;
case 74:
_context.next = 76;
return _iterator2.next();
if (_iteratorNormalCompletion2) {
_context.next = 87;
break;
}
case 76:
_step2 = _context.sent;
_iteratorNormalCompletion2 = _step2.done;
_context.next = 80;
return _step2.value;
chunk = _value2;
chunks.push(chunk);
case 80:
_value2 = _context.sent;
case 84:
_iteratorNormalCompletion2 = true;
_context.next = 74;
break;
if (_iteratorNormalCompletion2) {
_context.next = 87;
break;
}
case 87:
_context.next = 93;
break;
chunk = _value2;
chunks.push(chunk);
case 89:
_context.prev = 89;
_context.t3 = _context["catch"](72);
_didIteratorError2 = true;
_iteratorError2 = _context.t3;
case 84:
_iteratorNormalCompletion2 = true;
_context.next = 74;
break;
case 93:
_context.prev = 93;
_context.prev = 94;
case 87:
_context.next = 93;
if (!(!_iteratorNormalCompletion2 && _iterator2["return"] != null)) {
_context.next = 98;
break;
}
case 89:
_context.prev = 89;
_context.t3 = _context["catch"](72);
_didIteratorError2 = true;
_iteratorError2 = _context.t3;
_context.next = 98;
return _iterator2["return"]();
case 93:
_context.prev = 93;
_context.prev = 94;
case 98:
_context.prev = 98;
if (!(!_iteratorNormalCompletion2 && _iterator2["return"] != null)) {
_context.next = 98;
break;
}
if (!_didIteratorError2) {
_context.next = 101;
break;
}
_context.next = 98;
return _iterator2["return"]();
throw _iteratorError2;
case 98:
_context.prev = 98;
case 101:
return _context.finish(98);
if (!_didIteratorError2) {
_context.next = 101;
break;
}
case 102:
return _context.finish(93);
throw _iteratorError2;
case 103:
change = (0, _common.deserialize)((0, _concat["default"])(Buffer).call(Buffer, chunks).toString());
_context.next = 106;
return store.call('write', change, options);
case 101:
return _context.finish(98);
case 106:
_value4 = _context.sent;
res.writeHead(200);
res.end((0, _common.serialize)(_value4));
_context.next = 116;
break;
case 102:
return _context.finish(93);
case 111:
_context.prev = 111;
_context.t4 = _context["catch"](68);
res.writeHead(400);
res.end(_context.t4.message + "\n\n");
return _context.abrupt("return");
case 103:
change = JSON.parse((0, _concat["default"])(Buffer).call(Buffer, chunks).toString());
_context.next = 106;
return store.call('write', change, options);
case 116:
_context.next = 120;
break;
case 106:
_value4 = _context.sent;
res.writeHead(200);
res.end((0, _stringify["default"])(_value4));
_context.next = 116;
break;
case 118:
res.writeHead(501);
res.end('Not implemented');
case 111:
_context.prev = 111;
_context.t4 = _context["catch"](68);
res.writeHead(400);
res.end(_context.t4.message + "\n\n");
return _context.abrupt("return");
case 116:
_context.next = 120;
break;
case 118:
res.writeHead(501);
res.end('Not implemented');
case 120:
case "end":
return _context.stop();
}
case 120:
case "end":
return _context.stop();
}
}, _callee, null, [[4, 60], [8, 47], [12, 31, 35, 45], [36,, 40, 44], [68, 111], [72, 89, 93, 103], [94,, 98, 102]]);
}));
}
}, _callee, null, [[4, 60], [8, 47], [12, 31, 35, 45], [36,, 40, 44], [68, 111], [72, 89, 93, 103], [94,, 98, 102]]);
}));
return function (_x, _x2) {
return _ref.apply(this, arguments);
};
}()
);
return function (_x, _x2) {
return _ref.apply(this, arguments);
};
}();
} // TODO: Write tests!

@@ -309,0 +302,0 @@

@@ -5,3 +5,3 @@ {

"author": "aravind (https://github.com/aravindet)",
"version": "0.14.6-alpha1",
"version": "0.14.6-alpha10",
"main": "index.js",

@@ -16,7 +16,7 @@ "source": "src/index.js",

"dependencies": {
"@babel/runtime-corejs3": "^7.8.4",
"@babel/runtime-corejs3": "^7.9.2",
"url": "x",
"@graffy/common": "0.14.6-alpha1",
"ws": "^7.2.1"
"@graffy/common": "0.14.6-alpha10",
"ws": "^7.2.3"
}
}
import url from 'url';
import { decodeUrl } from '@graffy/common';
import { decodeUrl, serialize, deserialize } from '@graffy/common';

@@ -10,3 +10,3 @@ export default function server(store) {

const options =
parsed.query.opts && JSON.parse(decodeURIComponent(parsed.query.opts));
parsed.query.opts && deserialize(decodeURIComponent(parsed.query.opts));

@@ -35,3 +35,3 @@ if (req.method === 'GET') {

if (req.aborted || res.finished) break;
res.write(`data: ${JSON.stringify(value)}\n\n`);
res.write(`data: ${serialize(value)}\n\n`);
}

@@ -48,3 +48,3 @@ } catch (e) {

res.writeHead(200);
res.end(JSON.stringify(value));
res.end(serialize(value));
}

@@ -60,6 +60,6 @@ } catch (e) {

for await (const chunk of req) chunks.push(chunk);
const change = JSON.parse(Buffer.concat(chunks).toString());
const change = deserialize(Buffer.concat(chunks).toString());
const value = await store.call('write', change, options);
res.writeHead(200);
res.end(JSON.stringify(value));
res.end(serialize(value));
} catch (e) {

@@ -66,0 +66,0 @@ res.writeHead(400);

import WebSocket from 'ws';
import { serialize, deserialize } from '@graffy/common';

@@ -14,3 +15,3 @@ const PING_INTERVAL = 30000;

try {
const [id, op, payload, options] = JSON.parse(msg);
const [id, op, payload, options] = deserialize(msg);

@@ -27,5 +28,5 @@ if (id === ':pong') {

const result = await store.call(op, payload, options);
ws.send(JSON.stringify([id, null, result]));
ws.send(serialize([id, null, result]));
} catch (e) {
ws.send(JSON.stringify([id, e.message]));
ws.send(serialize([id, e.message]));
}

@@ -43,6 +44,6 @@ break;

for await (const value of stream) {
ws.send(JSON.stringify([id, null, value]));
ws.send(serialize([id, null, value]));
}
} catch (e) {
ws.send(JSON.stringify([id, e.message]));
ws.send(serialize([id, e.message]));
}

@@ -73,3 +74,3 @@ break;

ws.pingPending = true;
ws.send(JSON.stringify([':ping']));
ws.send(serialize([':ping']));
});

@@ -76,0 +77,0 @@ }, PING_INTERVAL);

@@ -16,4 +16,2 @@ "use strict";

var _stringify = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/json/stringify"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/asyncToGenerator"));

@@ -25,2 +23,4 @@

var _common = require("@graffy/common");
var PING_INTERVAL = 30000;

@@ -36,9 +36,5 @@

ws.on('message',
/*#__PURE__*/
function () {
var _message = (0, _asyncToGenerator2["default"])(
/*#__PURE__*/
_regenerator["default"].mark(function _callee(msg) {
var _JSON$parse, id, op, payload, options, result, stream, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, value;
ws.on('message', /*#__PURE__*/function () {
var _message = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(msg) {
var _deserialize, id, op, payload, options, result, stream, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, value;

@@ -50,3 +46,3 @@ return _regenerator["default"].wrap(function _callee$(_context) {

_context.prev = 0;
_JSON$parse = JSON.parse(msg), id = _JSON$parse[0], op = _JSON$parse[1], payload = _JSON$parse[2], options = _JSON$parse[3];
_deserialize = (0, _common.deserialize)(msg), id = _deserialize[0], op = _deserialize[1], payload = _deserialize[2], options = _deserialize[3];

@@ -73,3 +69,3 @@ if (!(id === ':pong')) {

result = _context.sent;
ws.send((0, _stringify["default"])([id, null, result]));
ws.send((0, _common.serialize)([id, null, result]));
_context.next = 18;

@@ -81,3 +77,3 @@ break;

_context.t1 = _context["catch"](8);
ws.send((0, _stringify["default"])([id, _context.t1.message]));
ws.send((0, _common.serialize)([id, _context.t1.message]));

@@ -117,3 +113,3 @@ case 18:

value = _value;
ws.send((0, _stringify["default"])([id, null, value]));
ws.send((0, _common.serialize)([id, null, value]));

@@ -170,3 +166,3 @@ case 36:

_context.t3 = _context["catch"](19);
ws.send((0, _stringify["default"])([id, _context.t3.message]));
ws.send((0, _common.serialize)([id, _context.t3.message]));

@@ -225,34 +221,29 @@ case 60:

ws.pingPending = true;
ws.send((0, _stringify["default"])([':ping']));
ws.send((0, _common.serialize)([':ping']));
});
}, PING_INTERVAL);
return (
/*#__PURE__*/
function () {
var _ref = (0, _asyncToGenerator2["default"])(
/*#__PURE__*/
_regenerator["default"].mark(function _callee2(request, socket, head) {
return _regenerator["default"].wrap(function _callee2$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
wss.handleUpgrade(request, socket, head, function done(ws) {
wss.emit('connection', ws, request);
});
return /*#__PURE__*/function () {
var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(request, socket, head) {
return _regenerator["default"].wrap(function _callee2$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
wss.handleUpgrade(request, socket, head, function done(ws) {
wss.emit('connection', ws, request);
});
case 1:
case "end":
return _context3.stop();
}
case 1:
case "end":
return _context3.stop();
}
}, _callee2);
}));
}
}, _callee2);
}));
return function (_x2, _x3, _x4) {
return _ref.apply(this, arguments);
};
}()
);
return function (_x2, _x3, _x4) {
return _ref.apply(this, arguments);
};
}();
}
module.exports = exports.default;
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