@truenas/api-client 1.0.0 → 1.0.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.
package/dist/index.cjs CHANGED
@@ -710,7 +710,9 @@ var TrueNasConnection = class {
710
710
  */
711
711
  this.messages$ = this.ws$.pipe(
712
712
  rxjs.filter((ws) => ws !== null),
713
- rxjs.switchMap((ws) => ws.messages())
713
+ rxjs.switchMap((ws) => ws.messages().pipe(
714
+ rxjs.catchError(() => rxjs.EMPTY)
715
+ ))
714
716
  );
715
717
  rxjs.combineLatest([
716
718
  rxjs.interval(twentySeconds),
@@ -737,11 +739,6 @@ var TrueNasConnection = class {
737
739
  *
738
740
  * `true` when the lifetime `connectionAttempts` count exceeds `hostnames.length * maxRetry`,
739
741
  * OR when an error message is currently set. Ported from the source (tncui) behavior.
740
- *
741
- * CAVEAT (pre-existing tncui behavior, preserved here): `connectionAttempts` only ever grows —
742
- * it is never reset on a successful (re)connection — so over a long-lived connection with
743
- * reconnect churn this can latch to `true` even while the connection is currently healthy. For
744
- * "is it errored right now?" use the live `hasConnectionError$` observable instead.
745
742
  */
746
743
  hasExhaustedRetries() {
747
744
  const attemptsExhausted = this.connectionAttempts.value > this.hostnames.length * this.maxRetry;
@@ -787,11 +784,14 @@ var TrueNasConnection = class {
787
784
  */
788
785
  createSocket(hostname) {
789
786
  const url = `wss://${hostname}${this.websocketPath}`;
787
+ let hasOpened = false;
790
788
  return new rxjs.Observable((subscriber) => {
791
789
  const ws = new TrueNasSocket({
792
790
  url,
793
791
  openObserver: {
794
792
  next: () => {
793
+ hasOpened = true;
794
+ this.connectionAttempts.next(0);
795
795
  subscriber.next({ ws, hostname });
796
796
  }
797
797
  },
@@ -821,9 +821,21 @@ var TrueNasConnection = class {
821
821
  // retry logic:
822
822
  // * if a connection is not established in 10 seconds, consider that an error
823
823
  rxjs.timeout({ first: tenSeconds }),
824
- // * if an error happens, wait `retryDelay` before trying again.
825
- // after `maxRetry` retries, give up.
826
- rxjs.retry({ count: this.maxRetry, delay: this.retryDelay })
824
+ rxjs.retry({
825
+ // * while still *establishing*: wait `retryDelay` before trying again, giving up
826
+ // after `maxRetry` retries.
827
+ count: this.maxRetry,
828
+ // * we use a custom `delay` function here to ensure no retries are performed
829
+ // once a socket is *opened*.
830
+ // basically: a later death must propagate out rather than being retried
831
+ // so it can be handled by the `connection$` observable.
832
+ delay: (error) => {
833
+ if (hasOpened) {
834
+ return rxjs.throwError(() => error);
835
+ }
836
+ return rxjs.timer(this.retryDelay);
837
+ }
838
+ })
827
839
  );
828
840
  }
829
841
  /**
@@ -1286,7 +1298,7 @@ var VersionDiscovery = class {
1286
1298
  async fetchVersions(hostname) {
1287
1299
  const url = `https://${hostname}/api/versions`;
1288
1300
  const controller = new AbortController();
1289
- const timer = setTimeout(() => controller.abort(), discoveryTimeoutMs);
1301
+ const timer2 = setTimeout(() => controller.abort(), discoveryTimeoutMs);
1290
1302
  try {
1291
1303
  const response = await fetch(url, { signal: controller.signal });
1292
1304
  if (response.status === 404) {
@@ -1307,7 +1319,7 @@ var VersionDiscovery = class {
1307
1319
  }
1308
1320
  return body;
1309
1321
  } finally {
1310
- clearTimeout(timer);
1322
+ clearTimeout(timer2);
1311
1323
  }
1312
1324
  }
1313
1325
  /**