@graffy/client 0.15.24-alpha.1 → 0.15.25-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
@@ -5,13 +5,11 @@ var __publicField = (obj, key, value) => {
5
5
  __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
6
6
  return value;
7
7
  };
8
- var common = require("@graffy/common");
9
- var stream = require("@graffy/stream");
10
- var debug = require("debug");
11
- function _interopDefaultLegacy(e) {
12
- return e && typeof e === "object" && "default" in e ? e : { "default": e };
13
- }
14
- var debug__default = /* @__PURE__ */ _interopDefaultLegacy(debug);
8
+ const common = require("@graffy/common");
9
+ const stream = require("@graffy/stream");
10
+ const debug = require("debug");
11
+ const _interopDefaultLegacy = (e) => e && typeof e === "object" && "default" in e ? e : { default: e };
12
+ const debug__default = /* @__PURE__ */ _interopDefaultLegacy(debug);
15
13
  function getOptionsParam(options) {
16
14
  if (!options)
17
15
  return "";
@@ -125,7 +123,7 @@ const httpClient = (baseUrl, {
125
123
  });
126
124
  });
127
125
  };
128
- const log = debug__default["default"]("graffy:client:socket");
126
+ const log = debug__default.default("graffy:client:socket");
129
127
  log.log = console.log.bind(console);
130
128
  const MIN_DELAY = 1e3;
131
129
  const MAX_DELAY = 3e5;
@@ -133,7 +131,7 @@ const DELAY_GROWTH = 1.5;
133
131
  const INTERVAL = 2e3;
134
132
  const PING_TIMEOUT = 4e4;
135
133
  const RESET_TIMEOUT = 1e4;
136
- function Socket(url, { onUnhandled, onStatusChange } = {}) {
134
+ function Socket(url, { onUnhandled = void 0, onStatusChange = void 0 } = {}) {
137
135
  const handlers = {};
138
136
  const buffer = [];
139
137
  let isOpen = false;
@@ -163,7 +161,7 @@ function Socket(url, { onUnhandled, onStatusChange } = {}) {
163
161
  isConnecting = true;
164
162
  lastAttempt = Date.now();
165
163
  attempts++;
166
- socket = new WebSocket(url);
164
+ socket = new globalThis.WebSocket(url);
167
165
  socket.onmessage = received;
168
166
  socket.onerror = closed;
169
167
  socket.onclose = closed;
@@ -252,11 +250,14 @@ function Socket(url, { onUnhandled, onStatusChange } = {}) {
252
250
  isAlive
253
251
  };
254
252
  }
255
- const wsClient = (url, { getOptions = () => {
256
- }, watch, connInfoPath = "connection" } = {}) => (store) => {
253
+ const wsClient = (url, {
254
+ getOptions = (..._) => false,
255
+ watch = void 0,
256
+ connInfoPath = "connection"
257
+ } = {}) => (store) => {
257
258
  if (!WebSocket)
258
259
  throw Error("client.websocket.unavailable");
259
- const socket = new Socket(url, { onUnhandled, onStatusChange });
260
+ const socket = Socket(url, { onUnhandled, onStatusChange });
260
261
  let status = false;
261
262
  const statusWatcher = common.makeWatcher();
262
263
  function onUnhandled(id) {
@@ -268,10 +269,13 @@ const wsClient = (url, { getOptions = () => {
268
269
  }
269
270
  function once(op, payload, options) {
270
271
  return new Promise((resolve, reject) => {
271
- const id = socket.start([op, payload, getOptions(op, options) || {}], (error, result) => {
272
- socket.stop(id);
273
- error ? reject(Error("server." + error)) : resolve(result);
274
- });
272
+ const id = socket.start(
273
+ [op, payload, getOptions(op, options) || {}],
274
+ (error, result) => {
275
+ socket.stop(id);
276
+ error ? reject(Error("server." + error)) : resolve(result);
277
+ }
278
+ );
275
279
  });
276
280
  }
277
281
  store.onWrite(connInfoPath, () => {
@@ -287,14 +291,17 @@ const wsClient = (url, { getOptions = () => {
287
291
  throw Error("client.no_watch");
288
292
  const op = "watch";
289
293
  return stream.makeStream((push, end) => {
290
- const id = socket.start([op, query, getOptions(op, options) || {}], (error, result) => {
291
- if (error) {
292
- socket.stop(id);
293
- end(Error("server." + error));
294
- return;
294
+ const id = socket.start(
295
+ [op, query, getOptions(op, options) || {}],
296
+ (error, result) => {
297
+ if (error) {
298
+ socket.stop(id);
299
+ end(Error("server." + error));
300
+ return;
301
+ }
302
+ push(result);
295
303
  }
296
- push(result);
297
- });
304
+ );
298
305
  return () => {
299
306
  socket.stop(id, ["unwatch"]);
300
307
  };
package/index.mjs CHANGED
@@ -128,7 +128,7 @@ const DELAY_GROWTH = 1.5;
128
128
  const INTERVAL = 2e3;
129
129
  const PING_TIMEOUT = 4e4;
130
130
  const RESET_TIMEOUT = 1e4;
131
- function Socket(url, { onUnhandled, onStatusChange } = {}) {
131
+ function Socket(url, { onUnhandled = void 0, onStatusChange = void 0 } = {}) {
132
132
  const handlers = {};
133
133
  const buffer = [];
134
134
  let isOpen = false;
@@ -158,7 +158,7 @@ function Socket(url, { onUnhandled, onStatusChange } = {}) {
158
158
  isConnecting = true;
159
159
  lastAttempt = Date.now();
160
160
  attempts++;
161
- socket = new WebSocket(url);
161
+ socket = new globalThis.WebSocket(url);
162
162
  socket.onmessage = received;
163
163
  socket.onerror = closed;
164
164
  socket.onclose = closed;
@@ -247,11 +247,14 @@ function Socket(url, { onUnhandled, onStatusChange } = {}) {
247
247
  isAlive
248
248
  };
249
249
  }
250
- const wsClient = (url, { getOptions = () => {
251
- }, watch, connInfoPath = "connection" } = {}) => (store) => {
250
+ const wsClient = (url, {
251
+ getOptions = (..._) => false,
252
+ watch = void 0,
253
+ connInfoPath = "connection"
254
+ } = {}) => (store) => {
252
255
  if (!WebSocket)
253
256
  throw Error("client.websocket.unavailable");
254
- const socket = new Socket(url, { onUnhandled, onStatusChange });
257
+ const socket = Socket(url, { onUnhandled, onStatusChange });
255
258
  let status = false;
256
259
  const statusWatcher = makeWatcher();
257
260
  function onUnhandled(id) {
@@ -263,10 +266,13 @@ const wsClient = (url, { getOptions = () => {
263
266
  }
264
267
  function once(op, payload, options) {
265
268
  return new Promise((resolve, reject) => {
266
- const id = socket.start([op, payload, getOptions(op, options) || {}], (error, result) => {
267
- socket.stop(id);
268
- error ? reject(Error("server." + error)) : resolve(result);
269
- });
269
+ const id = socket.start(
270
+ [op, payload, getOptions(op, options) || {}],
271
+ (error, result) => {
272
+ socket.stop(id);
273
+ error ? reject(Error("server." + error)) : resolve(result);
274
+ }
275
+ );
270
276
  });
271
277
  }
272
278
  store.onWrite(connInfoPath, () => {
@@ -282,14 +288,17 @@ const wsClient = (url, { getOptions = () => {
282
288
  throw Error("client.no_watch");
283
289
  const op = "watch";
284
290
  return makeStream((push, end) => {
285
- const id = socket.start([op, query, getOptions(op, options) || {}], (error, result) => {
286
- if (error) {
287
- socket.stop(id);
288
- end(Error("server." + error));
289
- return;
291
+ const id = socket.start(
292
+ [op, query, getOptions(op, options) || {}],
293
+ (error, result) => {
294
+ if (error) {
295
+ socket.stop(id);
296
+ end(Error("server." + error));
297
+ return;
298
+ }
299
+ push(result);
290
300
  }
291
- push(result);
292
- });
301
+ );
293
302
  return () => {
294
303
  socket.stop(id, ["unwatch"]);
295
304
  };
@@ -304,4 +313,6 @@ function GraffyClient(baseUrl, options) {
304
313
  return httpClient(baseUrl, options);
305
314
  }
306
315
  }
307
- export { GraffyClient as default };
316
+ export {
317
+ GraffyClient as default
318
+ };
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.15.24-alpha.1",
5
+ "version": "0.15.25-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/stream": "0.15.24-alpha.1",
20
- "@graffy/common": "0.15.24-alpha.1",
19
+ "@graffy/common": "0.15.25-alpha.2",
20
+ "@graffy/stream": "0.15.25-alpha.2",
21
21
  "debug": "^4.3.3"
22
22
  }
23
23
  }
package/types/Socket.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export default function Socket(url: any, { onUnhandled, onStatusChange }?: {
2
- onUnhandled: any;
3
- onStatusChange: any;
2
+ onUnhandled?: any;
3
+ onStatusChange?: any;
4
4
  }): {
5
5
  start: (params: any, callback: any) => any;
6
6
  stop: (id: any, params: any) => void;
@@ -1,6 +1,6 @@
1
1
  export default wsClient;
2
- declare function wsClient(url: any, { getOptions, watch, connInfoPath }?: {
3
- getOptions?: () => void;
4
- watch: any;
2
+ declare function wsClient(url: any, { getOptions, watch, connInfoPath, }?: {
3
+ getOptions?: (..._: any[]) => false;
4
+ watch?: any;
5
5
  connInfoPath?: string;
6
6
  }): (store: any) => void;