@graffy/server 0.16.20-alpha.10 → 0.16.20-alpha.12

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,7 +6,8 @@ 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) throw new Error("server.store_undef");
9
+ if (!store)
10
+ throw new Error("server.store_undef");
10
11
  return async (req, res) => {
11
12
  const parsed = url.parse(req.url, true);
12
13
  const optParam = parsed.query.opts && String(parsed.query.opts);
@@ -30,7 +31,8 @@ function server$1(store, { auth } = {}) {
30
31
  raw: true
31
32
  });
32
33
  for await (const value of stream) {
33
- if (req.aborted || res.finished) break;
34
+ if (req.aborted || res.finished)
35
+ break;
34
36
  res.write(`data: ${JSON.stringify(common.pack(value))}
35
37
 
36
38
  `);
@@ -63,7 +65,8 @@ data: ${e.message}
63
65
  throw Error("httpServer.unsupported_op");
64
66
  }
65
67
  const chunks = [];
66
- for await (const chunk of req) chunks.push(chunk);
68
+ for await (const chunk of req)
69
+ chunks.push(chunk);
67
70
  const payload = common.unpack(JSON.parse(Buffer.concat(chunks).toString()));
68
71
  if (auth && !await auth(
69
72
  op,
@@ -108,7 +111,8 @@ data: ${e.message}
108
111
  const log = debug("graffy:server:ws");
109
112
  const PING_INTERVAL = 3e4;
110
113
  function server(store) {
111
- if (!store) throw new Error("server.store_undef");
114
+ if (!store)
115
+ throw new Error("server.store_undef");
112
116
  const wss = new ws.WebSocketServer({ noServer: true });
113
117
  wss.on("connection", function connection(ws2) {
114
118
  ws2.graffyStreams = {};
@@ -147,7 +151,8 @@ function server(store) {
147
151
  }
148
152
  break;
149
153
  case "unwatch":
150
- if (!ws2.graffyStreams[id]) break;
154
+ if (!ws2.graffyStreams[id])
155
+ break;
151
156
  ws2.graffyStreams[id].return();
152
157
  delete ws2.graffyStreams[id];
153
158
  break;
@@ -166,7 +171,8 @@ function server(store) {
166
171
  });
167
172
  setInterval(function ping() {
168
173
  wss.clients.forEach(function each(ws2) {
169
- if (ws2.pingPending) return ws2.terminate();
174
+ if (ws2.pingPending)
175
+ return ws2.terminate();
170
176
  ws2.pingPending = true;
171
177
  ws2.send(JSON.stringify([":ping", Date.now()]));
172
178
  });
package/index.mjs CHANGED
@@ -4,7 +4,8 @@ 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) throw new Error("server.store_undef");
7
+ if (!store)
8
+ throw new Error("server.store_undef");
8
9
  return async (req, res) => {
9
10
  const parsed = url.parse(req.url, true);
10
11
  const optParam = parsed.query.opts && String(parsed.query.opts);
@@ -28,7 +29,8 @@ function server$1(store, { auth } = {}) {
28
29
  raw: true
29
30
  });
30
31
  for await (const value of stream) {
31
- if (req.aborted || res.finished) break;
32
+ if (req.aborted || res.finished)
33
+ break;
32
34
  res.write(`data: ${JSON.stringify(pack(value))}
33
35
 
34
36
  `);
@@ -61,7 +63,8 @@ data: ${e.message}
61
63
  throw Error("httpServer.unsupported_op");
62
64
  }
63
65
  const chunks = [];
64
- for await (const chunk of req) chunks.push(chunk);
66
+ for await (const chunk of req)
67
+ chunks.push(chunk);
65
68
  const payload = unpack(JSON.parse(Buffer.concat(chunks).toString()));
66
69
  if (auth && !await auth(
67
70
  op,
@@ -106,7 +109,8 @@ data: ${e.message}
106
109
  const log = debug("graffy:server:ws");
107
110
  const PING_INTERVAL = 3e4;
108
111
  function server(store) {
109
- if (!store) throw new Error("server.store_undef");
112
+ if (!store)
113
+ throw new Error("server.store_undef");
110
114
  const wss = new WebSocketServer({ noServer: true });
111
115
  wss.on("connection", function connection(ws) {
112
116
  ws.graffyStreams = {};
@@ -145,7 +149,8 @@ function server(store) {
145
149
  }
146
150
  break;
147
151
  case "unwatch":
148
- if (!ws.graffyStreams[id]) break;
152
+ if (!ws.graffyStreams[id])
153
+ break;
149
154
  ws.graffyStreams[id].return();
150
155
  delete ws.graffyStreams[id];
151
156
  break;
@@ -164,7 +169,8 @@ function server(store) {
164
169
  });
165
170
  setInterval(function ping() {
166
171
  wss.clients.forEach(function each(ws) {
167
- if (ws.pingPending) return ws.terminate();
172
+ if (ws.pingPending)
173
+ return ws.terminate();
168
174
  ws.pingPending = true;
169
175
  ws.send(JSON.stringify([":ping", Date.now()]));
170
176
  });
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.20-alpha.10",
5
+ "version": "0.16.20-alpha.12",
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.20-alpha.10",
20
- "debug": "^4.3.7",
21
- "ws": "^8.18.0"
19
+ "@graffy/common": "0.16.20-alpha.12",
20
+ "debug": "^4.3.3",
21
+ "ws": "^8.17.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<any>;
12
+ export type GraffyStore = import('@graffy/core').default;