@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 +23 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +0 -5
- package/dist/index.d.ts +0 -5
- package/dist/index.js +24 -12
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1993,11 +1993,6 @@ declare class TrueNasConnection {
|
|
|
1993
1993
|
*
|
|
1994
1994
|
* `true` when the lifetime `connectionAttempts` count exceeds `hostnames.length * maxRetry`,
|
|
1995
1995
|
* OR when an error message is currently set. Ported from the source (tncui) behavior.
|
|
1996
|
-
*
|
|
1997
|
-
* CAVEAT (pre-existing tncui behavior, preserved here): `connectionAttempts` only ever grows —
|
|
1998
|
-
* it is never reset on a successful (re)connection — so over a long-lived connection with
|
|
1999
|
-
* reconnect churn this can latch to `true` even while the connection is currently healthy. For
|
|
2000
|
-
* "is it errored right now?" use the live `hasConnectionError$` observable instead.
|
|
2001
1996
|
*/
|
|
2002
1997
|
hasExhaustedRetries(): boolean;
|
|
2003
1998
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1993,11 +1993,6 @@ declare class TrueNasConnection {
|
|
|
1993
1993
|
*
|
|
1994
1994
|
* `true` when the lifetime `connectionAttempts` count exceeds `hostnames.length * maxRetry`,
|
|
1995
1995
|
* OR when an error message is currently set. Ported from the source (tncui) behavior.
|
|
1996
|
-
*
|
|
1997
|
-
* CAVEAT (pre-existing tncui behavior, preserved here): `connectionAttempts` only ever grows —
|
|
1998
|
-
* it is never reset on a successful (re)connection — so over a long-lived connection with
|
|
1999
|
-
* reconnect churn this can latch to `true` even while the connection is currently healthy. For
|
|
2000
|
-
* "is it errored right now?" use the live `hasConnectionError$` observable instead.
|
|
2001
1996
|
*/
|
|
2002
1997
|
hasExhaustedRetries(): boolean;
|
|
2003
1998
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { switchMap, map, toArray, concat, from, defer, throwError, firstValueFrom, BehaviorSubject, Subject, distinctUntilChanged, of, filter, take, catchError as catchError$1, retry, startWith, shareReplay as shareReplay$1, takeUntil, combineLatest, interval, Observable, timeout, race, tap, share, takeWhile, merge, finalize } from 'rxjs';
|
|
1
|
+
import { switchMap, map, toArray, concat, from, defer, throwError, firstValueFrom, BehaviorSubject, Subject, distinctUntilChanged, of, filter, take, catchError as catchError$1, retry, startWith, shareReplay as shareReplay$1, takeUntil, EMPTY, combineLatest, interval, Observable, timeout, timer, race, tap, share, takeWhile, merge, finalize } from 'rxjs';
|
|
2
2
|
import { webSocket } from 'rxjs/webSocket';
|
|
3
3
|
import { map as map$1, catchError, shareReplay } from 'rxjs/operators';
|
|
4
4
|
|
|
@@ -708,7 +708,9 @@ var TrueNasConnection = class {
|
|
|
708
708
|
*/
|
|
709
709
|
this.messages$ = this.ws$.pipe(
|
|
710
710
|
filter((ws) => ws !== null),
|
|
711
|
-
switchMap((ws) => ws.messages()
|
|
711
|
+
switchMap((ws) => ws.messages().pipe(
|
|
712
|
+
catchError$1(() => EMPTY)
|
|
713
|
+
))
|
|
712
714
|
);
|
|
713
715
|
combineLatest([
|
|
714
716
|
interval(twentySeconds),
|
|
@@ -735,11 +737,6 @@ var TrueNasConnection = class {
|
|
|
735
737
|
*
|
|
736
738
|
* `true` when the lifetime `connectionAttempts` count exceeds `hostnames.length * maxRetry`,
|
|
737
739
|
* OR when an error message is currently set. Ported from the source (tncui) behavior.
|
|
738
|
-
*
|
|
739
|
-
* CAVEAT (pre-existing tncui behavior, preserved here): `connectionAttempts` only ever grows —
|
|
740
|
-
* it is never reset on a successful (re)connection — so over a long-lived connection with
|
|
741
|
-
* reconnect churn this can latch to `true` even while the connection is currently healthy. For
|
|
742
|
-
* "is it errored right now?" use the live `hasConnectionError$` observable instead.
|
|
743
740
|
*/
|
|
744
741
|
hasExhaustedRetries() {
|
|
745
742
|
const attemptsExhausted = this.connectionAttempts.value > this.hostnames.length * this.maxRetry;
|
|
@@ -785,11 +782,14 @@ var TrueNasConnection = class {
|
|
|
785
782
|
*/
|
|
786
783
|
createSocket(hostname) {
|
|
787
784
|
const url = `wss://${hostname}${this.websocketPath}`;
|
|
785
|
+
let hasOpened = false;
|
|
788
786
|
return new Observable((subscriber) => {
|
|
789
787
|
const ws = new TrueNasSocket({
|
|
790
788
|
url,
|
|
791
789
|
openObserver: {
|
|
792
790
|
next: () => {
|
|
791
|
+
hasOpened = true;
|
|
792
|
+
this.connectionAttempts.next(0);
|
|
793
793
|
subscriber.next({ ws, hostname });
|
|
794
794
|
}
|
|
795
795
|
},
|
|
@@ -819,9 +819,21 @@ var TrueNasConnection = class {
|
|
|
819
819
|
// retry logic:
|
|
820
820
|
// * if a connection is not established in 10 seconds, consider that an error
|
|
821
821
|
timeout({ first: tenSeconds }),
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
822
|
+
retry({
|
|
823
|
+
// * while still *establishing*: wait `retryDelay` before trying again, giving up
|
|
824
|
+
// after `maxRetry` retries.
|
|
825
|
+
count: this.maxRetry,
|
|
826
|
+
// * we use a custom `delay` function here to ensure no retries are performed
|
|
827
|
+
// once a socket is *opened*.
|
|
828
|
+
// basically: a later death must propagate out rather than being retried
|
|
829
|
+
// so it can be handled by the `connection$` observable.
|
|
830
|
+
delay: (error) => {
|
|
831
|
+
if (hasOpened) {
|
|
832
|
+
return throwError(() => error);
|
|
833
|
+
}
|
|
834
|
+
return timer(this.retryDelay);
|
|
835
|
+
}
|
|
836
|
+
})
|
|
825
837
|
);
|
|
826
838
|
}
|
|
827
839
|
/**
|
|
@@ -1284,7 +1296,7 @@ var VersionDiscovery = class {
|
|
|
1284
1296
|
async fetchVersions(hostname) {
|
|
1285
1297
|
const url = `https://${hostname}/api/versions`;
|
|
1286
1298
|
const controller = new AbortController();
|
|
1287
|
-
const
|
|
1299
|
+
const timer2 = setTimeout(() => controller.abort(), discoveryTimeoutMs);
|
|
1288
1300
|
try {
|
|
1289
1301
|
const response = await fetch(url, { signal: controller.signal });
|
|
1290
1302
|
if (response.status === 404) {
|
|
@@ -1305,7 +1317,7 @@ var VersionDiscovery = class {
|
|
|
1305
1317
|
}
|
|
1306
1318
|
return body;
|
|
1307
1319
|
} finally {
|
|
1308
|
-
clearTimeout(
|
|
1320
|
+
clearTimeout(timer2);
|
|
1309
1321
|
}
|
|
1310
1322
|
}
|
|
1311
1323
|
/**
|