@graffy/client 0.16.0-alpha.4 → 0.16.0-alpha.6

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
@@ -37,7 +37,7 @@ class AggregateQuery {
37
37
  const response = await fetch(this.url, {
38
38
  method: "POST",
39
39
  headers: { "Content-Type": "application/json" },
40
- body: common.serialize(this.combinedQuery)
40
+ body: JSON.stringify(common.pack(this.combinedQuery))
41
41
  });
42
42
  if (response.status !== 200) {
43
43
  const message = await response.text();
@@ -47,7 +47,7 @@ class AggregateQuery {
47
47
  }
48
48
  return;
49
49
  }
50
- const data = common.deserialize(await response.text());
50
+ const data = common.unpack(JSON.parse(await response.text()));
51
51
  for (const reader of this.readers) {
52
52
  reader.resolve(data);
53
53
  }
@@ -89,15 +89,15 @@ const httpClient = (baseUrl, {
89
89
  throw Error("client.sse.unavailable");
90
90
  const optionsParam = getOptionsParam(await getOptions("watch", options));
91
91
  const url = `${baseUrl}?q=${encodeURIComponent(
92
- common.serialize(query)
92
+ JSON.stringify(common.pack(query))
93
93
  )}&opts=${optionsParam}`;
94
94
  const source = new EventSource(url);
95
95
  yield* stream.makeStream((push, end) => {
96
96
  source.onmessage = ({ data }) => {
97
- push(common.deserialize(data));
97
+ push(common.unpack(JSON.parse(data)));
98
98
  };
99
99
  source.onerror = (e) => {
100
- end(Error("client.sse.transport: " + e.message));
100
+ end(Error("client.sse.transport: " + e));
101
101
  };
102
102
  source.addEventListener("graffyerror", (e) => {
103
103
  end(Error("server." + e.data));
@@ -115,10 +115,10 @@ const httpClient = (baseUrl, {
115
115
  return fetch(url, {
116
116
  method: "POST",
117
117
  headers: { "Content-Type": "application/json" },
118
- body: common.serialize(change)
118
+ body: JSON.stringify(common.pack(change))
119
119
  }).then(async (res) => {
120
120
  if (res.status === 200)
121
- return common.deserialize(await res.text());
121
+ return common.unpack(JSON.parse(await res.text()));
122
122
  return res.text().then((message) => {
123
123
  throw Error("server." + message);
124
124
  });
@@ -170,7 +170,7 @@ function Socket(url, { onUnhandled = void 0, onStatusChange = void 0 } = {}) {
170
170
  socket.onopen = opened;
171
171
  }
172
172
  function received(event) {
173
- const [id, ...data] = common.deserialize(event.data);
173
+ const [id, ...data] = JSON.parse(event.data);
174
174
  setAlive();
175
175
  if (id === ":ping") {
176
176
  send([":pong"]);
@@ -234,12 +234,13 @@ function Socket(url, { onUnhandled = void 0, onStatusChange = void 0 } = {}) {
234
234
  }
235
235
  if (Date.now() - lastAlive < PING_TIMEOUT)
236
236
  return true;
237
+ log("Ping timeout, closing", lastAlive);
237
238
  socket.close();
238
239
  return false;
239
240
  }
240
241
  function send(req) {
241
242
  if (isAlive()) {
242
- socket.send(common.serialize(req));
243
+ socket.send(JSON.stringify(req));
243
244
  } else {
244
245
  buffer.push(req);
245
246
  }
@@ -272,10 +273,10 @@ const wsClient = (url, {
272
273
  function once(op, payload, options) {
273
274
  return new Promise((resolve, reject) => {
274
275
  const id = socket.start(
275
- [op, payload, getOptions(op, options) || {}],
276
+ [op, common.pack(payload), getOptions(op, options) || {}],
276
277
  (error, result) => {
277
278
  socket.stop(id);
278
- error ? reject(Error("server." + error)) : resolve(result);
279
+ error ? reject(Error("server." + error)) : resolve(common.unpack(result));
279
280
  }
280
281
  );
281
282
  });
@@ -294,14 +295,14 @@ const wsClient = (url, {
294
295
  const op = "watch";
295
296
  return stream.makeStream((push, end) => {
296
297
  const id = socket.start(
297
- [op, query, getOptions(op, options) || {}],
298
+ [op, common.pack(query), getOptions(op, options) || {}],
298
299
  (error, result) => {
299
300
  if (error) {
300
301
  socket.stop(id);
301
302
  end(Error("server." + error));
302
303
  return;
303
304
  }
304
- push(result);
305
+ push(common.unpack(result));
305
306
  }
306
307
  );
307
308
  return () => {
package/index.mjs CHANGED
@@ -4,7 +4,7 @@ var __publicField = (obj, key, value) => {
4
4
  __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
5
  return value;
6
6
  };
7
- import { serialize, deserialize, add, makeId, makeWatcher } from "@graffy/common";
7
+ import { pack, unpack, add, makeId, makeWatcher } from "@graffy/common";
8
8
  import { makeStream } from "@graffy/stream";
9
9
  import debug from "debug";
10
10
  function getOptionsParam(options) {
@@ -34,7 +34,7 @@ class AggregateQuery {
34
34
  const response = await fetch(this.url, {
35
35
  method: "POST",
36
36
  headers: { "Content-Type": "application/json" },
37
- body: serialize(this.combinedQuery)
37
+ body: JSON.stringify(pack(this.combinedQuery))
38
38
  });
39
39
  if (response.status !== 200) {
40
40
  const message = await response.text();
@@ -44,7 +44,7 @@ class AggregateQuery {
44
44
  }
45
45
  return;
46
46
  }
47
- const data = deserialize(await response.text());
47
+ const data = unpack(JSON.parse(await response.text()));
48
48
  for (const reader of this.readers) {
49
49
  reader.resolve(data);
50
50
  }
@@ -86,15 +86,15 @@ const httpClient = (baseUrl, {
86
86
  throw Error("client.sse.unavailable");
87
87
  const optionsParam = getOptionsParam(await getOptions("watch", options));
88
88
  const url = `${baseUrl}?q=${encodeURIComponent(
89
- serialize(query)
89
+ JSON.stringify(pack(query))
90
90
  )}&opts=${optionsParam}`;
91
91
  const source = new EventSource(url);
92
92
  yield* makeStream((push, end) => {
93
93
  source.onmessage = ({ data }) => {
94
- push(deserialize(data));
94
+ push(unpack(JSON.parse(data)));
95
95
  };
96
96
  source.onerror = (e) => {
97
- end(Error("client.sse.transport: " + e.message));
97
+ end(Error("client.sse.transport: " + e));
98
98
  };
99
99
  source.addEventListener("graffyerror", (e) => {
100
100
  end(Error("server." + e.data));
@@ -112,10 +112,10 @@ const httpClient = (baseUrl, {
112
112
  return fetch(url, {
113
113
  method: "POST",
114
114
  headers: { "Content-Type": "application/json" },
115
- body: serialize(change)
115
+ body: JSON.stringify(pack(change))
116
116
  }).then(async (res) => {
117
117
  if (res.status === 200)
118
- return deserialize(await res.text());
118
+ return unpack(JSON.parse(await res.text()));
119
119
  return res.text().then((message) => {
120
120
  throw Error("server." + message);
121
121
  });
@@ -167,7 +167,7 @@ function Socket(url, { onUnhandled = void 0, onStatusChange = void 0 } = {}) {
167
167
  socket.onopen = opened;
168
168
  }
169
169
  function received(event) {
170
- const [id, ...data] = deserialize(event.data);
170
+ const [id, ...data] = JSON.parse(event.data);
171
171
  setAlive();
172
172
  if (id === ":ping") {
173
173
  send([":pong"]);
@@ -231,12 +231,13 @@ function Socket(url, { onUnhandled = void 0, onStatusChange = void 0 } = {}) {
231
231
  }
232
232
  if (Date.now() - lastAlive < PING_TIMEOUT)
233
233
  return true;
234
+ log("Ping timeout, closing", lastAlive);
234
235
  socket.close();
235
236
  return false;
236
237
  }
237
238
  function send(req) {
238
239
  if (isAlive()) {
239
- socket.send(serialize(req));
240
+ socket.send(JSON.stringify(req));
240
241
  } else {
241
242
  buffer.push(req);
242
243
  }
@@ -269,10 +270,10 @@ const wsClient = (url, {
269
270
  function once(op, payload, options) {
270
271
  return new Promise((resolve, reject) => {
271
272
  const id = socket.start(
272
- [op, payload, getOptions(op, options) || {}],
273
+ [op, pack(payload), getOptions(op, options) || {}],
273
274
  (error, result) => {
274
275
  socket.stop(id);
275
- error ? reject(Error("server." + error)) : resolve(result);
276
+ error ? reject(Error("server." + error)) : resolve(unpack(result));
276
277
  }
277
278
  );
278
279
  });
@@ -291,14 +292,14 @@ const wsClient = (url, {
291
292
  const op = "watch";
292
293
  return makeStream((push, end) => {
293
294
  const id = socket.start(
294
- [op, query, getOptions(op, options) || {}],
295
+ [op, pack(query), getOptions(op, options) || {}],
295
296
  (error, result) => {
296
297
  if (error) {
297
298
  socket.stop(id);
298
299
  end(Error("server." + error));
299
300
  return;
300
301
  }
301
- push(result);
302
+ push(unpack(result));
302
303
  }
303
304
  );
304
305
  return () => {
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@graffy/client",
3
3
  "description": "Graffy client library for the browser, usin the `fetch()` or `WebSocket` APIs. This module is intended to be used with a Node.js server running Graffy Server.",
4
4
  "author": "aravind (https://github.com/aravindet)",
5
- "version": "0.16.0-alpha.4",
5
+ "version": "0.16.0-alpha.6",
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-alpha.4",
20
- "@graffy/stream": "0.16.0-alpha.4",
19
+ "@graffy/common": "0.16.0-alpha.6",
20
+ "@graffy/stream": "0.16.0-alpha.6",
21
21
  "debug": "^4.3.3"
22
22
  }
23
23
  }
@@ -3,14 +3,14 @@ export default httpClient;
3
3
  *
4
4
  * @param {string} baseUrl
5
5
  * @param {{
6
- * getOptions?: () => Promise<void>,
6
+ * getOptions?: (op: string, options: any) => Promise<void>,
7
7
  * watch?: 'sse' | 'none' | 'hang',
8
8
  * connInfoPath?: string,
9
9
  * } | undefined} options
10
10
  * @returns {(store: any) => void}
11
11
  */
12
12
  declare function httpClient(baseUrl: string, { getOptions, watch, connInfoPath, }?: {
13
- getOptions?: () => Promise<void>;
13
+ getOptions?: (op: string, options: any) => Promise<void>;
14
14
  watch?: 'sse' | 'none' | 'hang';
15
15
  connInfoPath?: string;
16
- } | undefined): (store: any) => void;
16
+ }): (store: any) => void;