@graffy/server 0.16.0 → 0.16.2-alpha.1

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.
Files changed (3) hide show
  1. package/index.cjs +8 -11
  2. package/index.mjs +4 -4
  3. package/package.json +3 -3
package/index.cjs CHANGED
@@ -1,18 +1,15 @@
1
1
  "use strict";
2
- Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const url = require("url");
4
4
  const common = require("@graffy/common");
5
5
  const debug = require("debug");
6
6
  const ws = require("ws");
7
- const _interopDefaultLegacy = (e) => e && typeof e === "object" && "default" in e ? e : { default: e };
8
- const url__default = /* @__PURE__ */ _interopDefaultLegacy(url);
9
- const debug__default = /* @__PURE__ */ _interopDefaultLegacy(debug);
10
- const log$1 = debug__default.default("graffy:server:http");
7
+ const log$1 = debug("graffy:server:http");
11
8
  function server$1(store, { auth } = {}) {
12
9
  if (!store)
13
10
  throw new Error("server.store_undef");
14
11
  return async (req, res) => {
15
- const parsed = url__default.default.parse(req.url, true);
12
+ const parsed = url.parse(req.url, true);
16
13
  const optParam = parsed.query.opts && String(parsed.query.opts);
17
14
  const options = optParam && JSON.parse(decodeURIComponent(optParam));
18
15
  if (req.method === "GET") {
@@ -61,7 +58,7 @@ data: ${e.message}
61
58
  try {
62
59
  const op = parsed.query.op;
63
60
  if (op !== "write" && op !== "read") {
64
- throw Error("httpServer.unsupported_op: " + op);
61
+ throw Error(`httpServer.unsupported_op: ${op}`);
65
62
  }
66
63
  const chunks = [];
67
64
  for await (const chunk of req)
@@ -91,7 +88,7 @@ data: ${e.message}
91
88
  }
92
89
  };
93
90
  }
94
- const log = debug__default.default("graffy:server:ws");
91
+ const log = debug("graffy:server:ws");
95
92
  const PING_INTERVAL = 3e4;
96
93
  function server(store) {
97
94
  if (!store)
@@ -114,7 +111,7 @@ function server(store) {
114
111
  const result = await store.call(op, payload, options);
115
112
  ws2.send(JSON.stringify([id, null, common.pack(result)]));
116
113
  } catch (e) {
117
- log(op + "error:" + e.message + " " + payload);
114
+ log(`${op}error:${e.message} ${payload}`);
118
115
  ws2.send(JSON.stringify([id, e.message]));
119
116
  }
120
117
  break;
@@ -129,7 +126,7 @@ function server(store) {
129
126
  ws2.send(JSON.stringify([id, null, common.pack(value)]));
130
127
  }
131
128
  } catch (e) {
132
- log(op + "error:" + e.message + " " + payload);
129
+ log(`${op}error:${e.message} ${payload}`);
133
130
  ws2.send(JSON.stringify([id, e.message]));
134
131
  }
135
132
  break;
@@ -141,7 +138,7 @@ function server(store) {
141
138
  break;
142
139
  }
143
140
  } catch (e) {
144
- log("Closing socket due to error: " + e.message);
141
+ log(`Closing socket due to error: ${e.message}`);
145
142
  ws2.close();
146
143
  }
147
144
  });
package/index.mjs CHANGED
@@ -56,7 +56,7 @@ data: ${e.message}
56
56
  try {
57
57
  const op = parsed.query.op;
58
58
  if (op !== "write" && op !== "read") {
59
- throw Error("httpServer.unsupported_op: " + op);
59
+ throw Error(`httpServer.unsupported_op: ${op}`);
60
60
  }
61
61
  const chunks = [];
62
62
  for await (const chunk of req)
@@ -109,7 +109,7 @@ function server(store) {
109
109
  const result = await store.call(op, payload, options);
110
110
  ws.send(JSON.stringify([id, null, pack(result)]));
111
111
  } catch (e) {
112
- log(op + "error:" + e.message + " " + payload);
112
+ log(`${op}error:${e.message} ${payload}`);
113
113
  ws.send(JSON.stringify([id, e.message]));
114
114
  }
115
115
  break;
@@ -124,7 +124,7 @@ function server(store) {
124
124
  ws.send(JSON.stringify([id, null, pack(value)]));
125
125
  }
126
126
  } catch (e) {
127
- log(op + "error:" + e.message + " " + payload);
127
+ log(`${op}error:${e.message} ${payload}`);
128
128
  ws.send(JSON.stringify([id, e.message]));
129
129
  }
130
130
  break;
@@ -136,7 +136,7 @@ function server(store) {
136
136
  break;
137
137
  }
138
138
  } catch (e) {
139
- log("Closing socket due to error: " + e.message);
139
+ log(`Closing socket due to error: ${e.message}`);
140
140
  ws.close();
141
141
  }
142
142
  });
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.0",
5
+ "version": "0.16.2-alpha.1",
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.0",
19
+ "@graffy/common": "0.16.2-alpha.1",
20
20
  "debug": "^4.3.3",
21
- "ws": "^8.4.2"
21
+ "ws": "^8.11.0"
22
22
  }
23
23
  }