@taybart/corvid 0.1.15 → 0.1.17

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/dist/index.js CHANGED
@@ -543,10 +543,12 @@ class request {
543
543
  const res = await fetch(url, options);
544
544
  const expect = override.expect || this.opts.expect;
545
545
  if (res.status !== expect) {
546
- const body = await res.json();
546
+ const body = await res.text();
547
547
  throw new Error(`bad response ${res.status} !== ${expect}, body: ${body}`);
548
548
  }
549
- return await res.json();
549
+ this.log.debug(`content type: ${res.headers.get('content-type')}`);
550
+ if ('application/json' === res.headers.get('content-type')) return await res.json();
551
+ return await res.text();
550
552
  }
551
553
  constructor(opts = {}, verbose = false){
552
554
  network_define_property(this, "opts", void 0);
@@ -576,12 +578,12 @@ class ws {
576
578
  this.backoff = 100;
577
579
  this.ws.addEventListener('open', ()=>{
578
580
  const rl = this.recursion_level;
579
- this.log.debug(`on open: reconnected (${rl})`);
581
+ this.log.debug(`on open: reconnected(${rl})`);
580
582
  this.is_connected = true;
581
583
  if (!this.ws) return;
582
584
  for(let key in this.event_listeners)this.event_listeners[key].forEach((cb)=>{
583
585
  if (this.ws) {
584
- this.log.debug(`adding listener (${rl}): ${key}`);
586
+ this.log.debug(`adding listener(${rl}): ${key} `);
585
587
  this.ws.addEventListener(key, cb);
586
588
  }
587
589
  });
@@ -590,7 +592,7 @@ class ws {
590
592
  this.log.debug('connection closed');
591
593
  this.is_connected = false;
592
594
  this.backoff = Math.min(2 * this.backoff, this.max_timeout);
593
- this.log.debug(`backoff: ${this.backoff}`);
595
+ this.log.debug(`backoff: ${this.backoff} `);
594
596
  this.reconnect_timer = window.setTimeout(()=>{
595
597
  if (this.should_reconnect) {
596
598
  this.ws = null;
@@ -609,7 +611,7 @@ class ws {
609
611
  if (!this.event_listeners.message) this.event_listeners.message = [];
610
612
  const handler = (e)=>{
611
613
  const rl = this.recursion_level;
612
- this.log.debug(`message(${rl}): ${e.data}`);
614
+ this.log.debug(`message(${rl}): ${e.data} `);
613
615
  cb(e.data);
614
616
  };
615
617
  this.event_listeners.message.push(handler);
@@ -674,7 +676,7 @@ const network = {
674
676
  };
675
677
  function get(key, _default) {
676
678
  let ret = localStorage.getItem(key);
677
- if (!ret && null != _default) {
679
+ if (null === ret && null != _default) {
678
680
  ret = _default;
679
681
  if ('function' == typeof _default) ret = _default();
680
682
  set(key, ret);
package/dist/ls.js CHANGED
@@ -244,7 +244,7 @@ function interpolate(str, params) {
244
244
  }
245
245
  function get(key, _default) {
246
246
  let ret = localStorage.getItem(key);
247
- if (!ret && null != _default) {
247
+ if (null === ret && null != _default) {
248
248
  ret = _default;
249
249
  if ('function' == typeof _default) ret = _default();
250
250
  set(key, ret);
package/dist/network.js CHANGED
@@ -140,10 +140,12 @@ class request {
140
140
  const res = await fetch(url, options);
141
141
  const expect = override.expect || this.opts.expect;
142
142
  if (res.status !== expect) {
143
- const body = await res.json();
143
+ const body = await res.text();
144
144
  throw new Error(`bad response ${res.status} !== ${expect}, body: ${body}`);
145
145
  }
146
- return await res.json();
146
+ this.log.debug(`content type: ${res.headers.get('content-type')}`);
147
+ if ('application/json' === res.headers.get('content-type')) return await res.json();
148
+ return await res.text();
147
149
  }
148
150
  constructor(opts = {}, verbose = false){
149
151
  network_define_property(this, "opts", void 0);
@@ -173,12 +175,12 @@ class ws {
173
175
  this.backoff = 100;
174
176
  this.ws.addEventListener('open', ()=>{
175
177
  const rl = this.recursion_level;
176
- this.log.debug(`on open: reconnected (${rl})`);
178
+ this.log.debug(`on open: reconnected(${rl})`);
177
179
  this.is_connected = true;
178
180
  if (!this.ws) return;
179
181
  for(let key in this.event_listeners)this.event_listeners[key].forEach((cb)=>{
180
182
  if (this.ws) {
181
- this.log.debug(`adding listener (${rl}): ${key}`);
183
+ this.log.debug(`adding listener(${rl}): ${key} `);
182
184
  this.ws.addEventListener(key, cb);
183
185
  }
184
186
  });
@@ -187,7 +189,7 @@ class ws {
187
189
  this.log.debug('connection closed');
188
190
  this.is_connected = false;
189
191
  this.backoff = Math.min(2 * this.backoff, this.max_timeout);
190
- this.log.debug(`backoff: ${this.backoff}`);
192
+ this.log.debug(`backoff: ${this.backoff} `);
191
193
  this.reconnect_timer = window.setTimeout(()=>{
192
194
  if (this.should_reconnect) {
193
195
  this.ws = null;
@@ -206,7 +208,7 @@ class ws {
206
208
  if (!this.event_listeners.message) this.event_listeners.message = [];
207
209
  const handler = (e)=>{
208
210
  const rl = this.recursion_level;
209
- this.log.debug(`message(${rl}): ${e.data}`);
211
+ this.log.debug(`message(${rl}): ${e.data} `);
210
212
  cb(e.data);
211
213
  };
212
214
  this.event_listeners.message.push(handler);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taybart/corvid",
3
- "version": "0.1.15",
3
+ "version": "0.1.17",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "exports": {