@rdlabo/ionic-angular-kit 22.0.0-beta.pr95.shac320513779dc → 22.0.0-beta.pr96.sha53b4ae63682a
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.
|
@@ -7,7 +7,7 @@ import { App } from '@capacitor/app';
|
|
|
7
7
|
import { Network } from '@capacitor/network';
|
|
8
8
|
import { Capacitor } from '@capacitor/core';
|
|
9
9
|
import { HttpErrorResponse, HttpContextToken, HttpResponse } from '@angular/common/http';
|
|
10
|
-
import { defer, from, map as map$1, catchError, throwError, concatMap, materialize, connect, concat, of, ReplaySubject, take, Observable, dematerialize, EMPTY, tap } from 'rxjs';
|
|
10
|
+
import { defer, from, map as map$1, catchError, throwError, concatMap, materialize, connect, concat, of, ReplaySubject, filter, NEVER, race, take, Observable, dematerialize, EMPTY, tap } from 'rxjs';
|
|
11
11
|
|
|
12
12
|
const MAX_OFFLINE_NATURAL_KEY_TEXT_BYTES = 1024;
|
|
13
13
|
const IDENTIFIER_PATTERN = /^[a-z][a-z0-9_]*$/;
|
|
@@ -5394,6 +5394,9 @@ const offlineInterceptor = (request, next) => {
|
|
|
5394
5394
|
if (plan.readStrategy === 'local-first') {
|
|
5395
5395
|
return readLocalFirst(request, plan, transport, fallback, inject(ErrorHandler), inject(OfflineReplicaMutationCoordinator));
|
|
5396
5396
|
}
|
|
5397
|
+
if (plan.readStrategy === 'fastest-first') {
|
|
5398
|
+
return readFastestFirst(request, plan, transport, fallback, inject(ErrorHandler), inject(OfflineReplicaMutationCoordinator));
|
|
5399
|
+
}
|
|
5397
5400
|
return readNetworkFirst(request, plan, transport, fallback);
|
|
5398
5401
|
}
|
|
5399
5402
|
if (LOCAL_FIRST_MUTATION_METHODS.has(request.method)) {
|
|
@@ -5427,6 +5430,21 @@ function readLocalFirst(request, plan, transport, fallback, errorHandler, replic
|
|
|
5427
5430
|
? concat(of(localResponse), drainRemoteAfterLocal(bufferedTransport$, plan))
|
|
5428
5431
|
: drainRemoteNetworkFirst(bufferedTransport$, request, plan, fallback))), { connector: () => new ReplaySubject() }));
|
|
5429
5432
|
}
|
|
5433
|
+
/** Races a serialized local replica read against remote transport without allowing stale local data to follow remote. */
|
|
5434
|
+
function readFastestFirst(request, plan, transport, fallback, errorHandler, replicaMutations) {
|
|
5435
|
+
return defer(transport).pipe(materialize(), connect((bufferedTransport$) => {
|
|
5436
|
+
const localDecision$ = resolveLocalAttempt(plan, errorHandler, replicaMutations).pipe(concatMap((localResponse) => localResponse
|
|
5437
|
+
? concat(of(localResponse), drainRemoteAfterLocal(bufferedTransport$, plan))
|
|
5438
|
+
: drainRemoteNetworkFirst(bufferedTransport$, request, plan, fallback)));
|
|
5439
|
+
// Angular transport emits Sent/progress events before the response.
|
|
5440
|
+
// They are not usable read results and therefore must not win the race.
|
|
5441
|
+
const remoteWinner$ = drainRemoteNetworkFirst(bufferedTransport$, request, plan, fallback).pipe(filter((event) => event instanceof HttpResponse),
|
|
5442
|
+
// A remote error is not a usable response. Keep it buffered until the
|
|
5443
|
+
// local attempt decides whether it can satisfy the read.
|
|
5444
|
+
catchError(() => NEVER));
|
|
5445
|
+
return race(localDecision$, remoteWinner$);
|
|
5446
|
+
}, { connector: () => new ReplaySubject() }));
|
|
5447
|
+
}
|
|
5430
5448
|
function resolveLocalAttempt(plan, errorHandler, replicaMutations) {
|
|
5431
5449
|
return serializedLocalRead(plan, replicaMutations).pipe(catchError((localError) => {
|
|
5432
5450
|
errorHandler.handleError(localError);
|