@graffy/server 0.16.19 → 0.16.20-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.cjs CHANGED
@@ -6,8 +6,7 @@ const debug = require("debug");
6
6
  const ws = require("ws");
7
7
  const log$1 = debug("graffy:server:http");
8
8
  function server$1(store, { auth } = {}) {
9
- if (!store)
10
- throw new Error("server.store_undef");
9
+ if (!store) throw new Error("server.store_undef");
11
10
  return async (req, res) => {
12
11
  const parsed = url.parse(req.url, true);
13
12
  const optParam = parsed.query.opts && String(parsed.query.opts);
@@ -31,8 +30,7 @@ function server$1(store, { auth } = {}) {
31
30
  raw: true
32
31
  });
33
32
  for await (const value of stream) {
34
- if (req.aborted || res.finished)
35
- break;
33
+ if (req.aborted || res.finished) break;
36
34
  res.write(`data: ${JSON.stringify(common.pack(value))}
37
35
 
38
36
  `);
@@ -65,8 +63,7 @@ data: ${e.message}
65
63
  throw Error("httpServer.unsupported_op");
66
64
  }
67
65
  const chunks = [];
68
- for await (const chunk of req)
69
- chunks.push(chunk);
66
+ for await (const chunk of req) chunks.push(chunk);
70
67
  const payload = common.unpack(JSON.parse(Buffer.concat(chunks).toString()));
71
68
  if (auth && !await auth(
72
69
  op,
@@ -111,8 +108,7 @@ data: ${e.message}
111
108
  const log = debug("graffy:server:ws");
112
109
  const PING_INTERVAL = 3e4;
113
110
  function server(store) {
114
- if (!store)
115
- throw new Error("server.store_undef");
111
+ if (!store) throw new Error("server.store_undef");
116
112
  const wss = new ws.WebSocketServer({ noServer: true });
117
113
  wss.on("connection", function connection(ws2) {
118
114
  ws2.graffyStreams = {};
@@ -151,8 +147,7 @@ function server(store) {
151
147
  }
152
148
  break;
153
149
  case "unwatch":
154
- if (!ws2.graffyStreams[id])
155
- break;
150
+ if (!ws2.graffyStreams[id]) break;
156
151
  ws2.graffyStreams[id].return();
157
152
  delete ws2.graffyStreams[id];
158
153
  break;
@@ -171,8 +166,7 @@ function server(store) {
171
166
  });
172
167
  setInterval(function ping() {
173
168
  wss.clients.forEach(function each(ws2) {
174
- if (ws2.pingPending)
175
- return ws2.terminate();
169
+ if (ws2.pingPending) return ws2.terminate();
176
170
  ws2.pingPending = true;
177
171
  ws2.send(JSON.stringify([":ping", Date.now()]));
178
172
  });
package/index.mjs CHANGED
@@ -4,8 +4,7 @@ import debug from "debug";
4
4
  import { WebSocketServer } from "ws";
5
5
  const log$1 = debug("graffy:server:http");
6
6
  function server$1(store, { auth } = {}) {
7
- if (!store)
8
- throw new Error("server.store_undef");
7
+ if (!store) throw new Error("server.store_undef");
9
8
  return async (req, res) => {
10
9
  const parsed = url.parse(req.url, true);
11
10
  const optParam = parsed.query.opts && String(parsed.query.opts);
@@ -29,8 +28,7 @@ function server$1(store, { auth } = {}) {
29
28
  raw: true
30
29
  });
31
30
  for await (const value of stream) {
32
- if (req.aborted || res.finished)
33
- break;
31
+ if (req.aborted || res.finished) break;
34
32
  res.write(`data: ${JSON.stringify(pack(value))}
35
33
 
36
34
  `);
@@ -63,8 +61,7 @@ data: ${e.message}
63
61
  throw Error("httpServer.unsupported_op");
64
62
  }
65
63
  const chunks = [];
66
- for await (const chunk of req)
67
- chunks.push(chunk);
64
+ for await (const chunk of req) chunks.push(chunk);
68
65
  const payload = unpack(JSON.parse(Buffer.concat(chunks).toString()));
69
66
  if (auth && !await auth(
70
67
  op,
@@ -109,8 +106,7 @@ data: ${e.message}
109
106
  const log = debug("graffy:server:ws");
110
107
  const PING_INTERVAL = 3e4;
111
108
  function server(store) {
112
- if (!store)
113
- throw new Error("server.store_undef");
109
+ if (!store) throw new Error("server.store_undef");
114
110
  const wss = new WebSocketServer({ noServer: true });
115
111
  wss.on("connection", function connection(ws) {
116
112
  ws.graffyStreams = {};
@@ -149,8 +145,7 @@ function server(store) {
149
145
  }
150
146
  break;
151
147
  case "unwatch":
152
- if (!ws.graffyStreams[id])
153
- break;
148
+ if (!ws.graffyStreams[id]) break;
154
149
  ws.graffyStreams[id].return();
155
150
  delete ws.graffyStreams[id];
156
151
  break;
@@ -169,8 +164,7 @@ function server(store) {
169
164
  });
170
165
  setInterval(function ping() {
171
166
  wss.clients.forEach(function each(ws) {
172
- if (ws.pingPending)
173
- return ws.terminate();
167
+ if (ws.pingPending) return ws.terminate();
174
168
  ws.pingPending = true;
175
169
  ws.send(JSON.stringify([":ping", Date.now()]));
176
170
  });
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@graffy/server",
3
3
  "description": "Node.js library for building an API for a Graffy store.",
4
4
  "author": "aravind (https://github.com/aravindet)",
5
- "version": "0.16.19",
5
+ "version": "0.16.20-alpha.2",
6
6
  "main": "./index.cjs",
7
7
  "exports": {
8
8
  "import": "./index.mjs",
@@ -16,8 +16,8 @@
16
16
  },
17
17
  "license": "Apache-2.0",
18
18
  "dependencies": {
19
- "@graffy/common": "0.16.19",
20
- "ws": "^8.17.0",
21
- "debug": "^4.3.3"
19
+ "@graffy/common": "0.16.20-alpha.2",
20
+ "debug": "^4.3.7",
21
+ "ws": "^8.18.0"
22
22
  }
23
23
  }
@@ -9,4 +9,4 @@
9
9
  export default function server(store: GraffyStore, { auth }?: {
10
10
  auth?: (operation: string, payload: any, options: any) => Promise<boolean>;
11
11
  } | undefined): (req: any, res: any) => Promise<void>;
12
- export type GraffyStore = import('@graffy/core').default;
12
+ export type GraffyStore = import("@graffy/core").default<any>;