@rdlabo/ionic-angular-kit 22.0.0-4 → 22.0.0-6
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/README.md +5 -6
- package/docs/offline-realtime.md +40 -0
- package/fesm2022/rdlabo-ionic-angular-kit-offline.mjs +235 -158
- package/fesm2022/rdlabo-ionic-angular-kit-offline.mjs.map +1 -1
- package/fesm2022/rdlabo-ionic-angular-kit.mjs +6 -1
- package/fesm2022/rdlabo-ionic-angular-kit.mjs.map +1 -1
- package/package.json +1 -1
- package/types/rdlabo-ionic-angular-kit-offline.d.ts +20 -1
- package/types/rdlabo-ionic-angular-kit.d.ts +3 -1
package/README.md
CHANGED
|
@@ -35,15 +35,14 @@ Secondary entry points isolate optional native and SDK dependencies from the cor
|
|
|
35
35
|
|
|
36
36
|
## Configure only what you use
|
|
37
37
|
|
|
38
|
-
Most features expose a provider whose callbacks keep routes, copy, credentials, and application side effects outside the kit. Start with [Storage and Overlays](
|
|
38
|
+
Most features expose a provider whose callbacks keep routes, copy, credentials, and application side effects outside the kit. Start with [Storage and Overlays](https://docs.rdlabo.dev/projects/ionic-angular-kit/docs/storage-overlays), then add authentication, offline, or native features as your app needs them.
|
|
39
39
|
|
|
40
40
|
## Documentation
|
|
41
41
|
|
|
42
|
-
- [Storage and Overlays](
|
|
43
|
-
- [Authentication and HTTP](
|
|
44
|
-
- [Offline and Realtime](
|
|
45
|
-
- [Optional Features](
|
|
46
|
-
- [Ionic Signal Forms](./docs/forms.md)
|
|
42
|
+
- [Storage and Overlays](https://docs.rdlabo.dev/projects/ionic-angular-kit/docs/storage-overlays)
|
|
43
|
+
- [Authentication and HTTP](https://docs.rdlabo.dev/projects/ionic-angular-kit/docs/auth-http)
|
|
44
|
+
- [Offline and Realtime](https://docs.rdlabo.dev/projects/ionic-angular-kit/docs/offline-realtime)
|
|
45
|
+
- [Optional Features](https://docs.rdlabo.dev/projects/ionic-angular-kit/docs/optional-features)
|
|
47
46
|
|
|
48
47
|
<!-- rdlabo-docs-omit -->
|
|
49
48
|
**Full documentation:** [https://docs.rdlabo.dev/projects/ionic-angular-kit](https://docs.rdlabo.dev/projects/ionic-angular-kit)
|
package/docs/offline-realtime.md
CHANGED
|
@@ -29,6 +29,46 @@ provideKitAuth(() => ({
|
|
|
29
29
|
|
|
30
30
|
On explicit sign-out, clear `KitAuthAccessService` first, then await offline session cleanup so in-flight leases are invalidated before persisted user data is removed.
|
|
31
31
|
|
|
32
|
+
### Lazy authenticated routes
|
|
33
|
+
|
|
34
|
+
Use `provideRouteScopedOffline()` when the offline runtime and product schema must not enter the
|
|
35
|
+
unauthenticated application graph. Unlike the root `provideOffline()` API, the route-scoped provider
|
|
36
|
+
creates isolated Kit service instances and does not start them automatically. This lets the product
|
|
37
|
+
finish native reset recovery before opening SQLite or IndexedDB.
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
import { inject } from '@angular/core';
|
|
41
|
+
import type { CanActivateFn, Routes } from '@angular/router';
|
|
42
|
+
import { OfflineRouteInitializerService, provideRouteScopedOffline } from '@rdlabo/ionic-angular-kit/offline';
|
|
43
|
+
|
|
44
|
+
const offlineReadyGuard: CanActivateFn = async () => {
|
|
45
|
+
await recoverProductOwnedLocalReset();
|
|
46
|
+
await inject(OfflineRouteInitializerService).initialize();
|
|
47
|
+
return true;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export const routes: Routes = [
|
|
51
|
+
{
|
|
52
|
+
path: '',
|
|
53
|
+
providers: [provideRouteScopedOffline(options)],
|
|
54
|
+
canActivate: [offlineReadyGuard],
|
|
55
|
+
children: [
|
|
56
|
+
{
|
|
57
|
+
path: '',
|
|
58
|
+
canActivate: [authorizedGuard],
|
|
59
|
+
loadComponent: () => import('./authenticated.page').then((module) => module.AuthenticatedPage),
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
},
|
|
63
|
+
];
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Use a parent/child route boundary when authorization depends on the initialized offline bridge. Do
|
|
67
|
+
not rely on ordering between guards declared in the same `canActivate` array.
|
|
68
|
+
|
|
69
|
+
Keep `provideOffline()` for existing root installations. Moving a provider is an application design
|
|
70
|
+
choice; adopting the new API is not a required migration.
|
|
71
|
+
|
|
32
72
|
## Realtime connection
|
|
33
73
|
|
|
34
74
|
Subclass `KitRealtimeConnection` to supply connection intent and `{ url, protocols }` targets. The kit owns foreground and network suspension, target-scoped reconnect, exponential backoff, ping/pong detection, self-echo annotation, and `reconnected$` resync signaling.
|
|
@@ -5366,6 +5366,143 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.3", ngImpor
|
|
|
5366
5366
|
args: [{ providedIn: 'root' }]
|
|
5367
5367
|
}] });
|
|
5368
5368
|
|
|
5369
|
+
const LOCAL_FIRST_MUTATION_METHODS = new Set(['POST', 'PUT', 'PATCH', 'DELETE']);
|
|
5370
|
+
/** Applies product read and local-first mutation policies while observing real API reachability. */
|
|
5371
|
+
const offlineInterceptor = (request, next) => {
|
|
5372
|
+
const network = inject(OfflineNetworkService);
|
|
5373
|
+
const transport = () => observeTransport(next(request), network);
|
|
5374
|
+
if (request.context.get(OFFLINE_BYPASS))
|
|
5375
|
+
return transport();
|
|
5376
|
+
if (request.method === 'GET') {
|
|
5377
|
+
const registry = inject(OfflineRequestPolicyRegistry);
|
|
5378
|
+
const fallback = inject(OfflineRequestFallbackService);
|
|
5379
|
+
const plan = registry.resolve(request);
|
|
5380
|
+
if (!plan)
|
|
5381
|
+
return transport();
|
|
5382
|
+
if (plan.readStrategy === 'local-first') {
|
|
5383
|
+
return readLocalFirst(request, plan, transport, fallback, inject(ErrorHandler), inject(OfflineReplicaMutationCoordinator));
|
|
5384
|
+
}
|
|
5385
|
+
return readNetworkFirst(request, plan, transport, fallback);
|
|
5386
|
+
}
|
|
5387
|
+
if (LOCAL_FIRST_MUTATION_METHODS.has(request.method)) {
|
|
5388
|
+
if (!inject(OFFLINE_MUTATION_PERSISTENCE_ENABLED)())
|
|
5389
|
+
return transport();
|
|
5390
|
+
const plan = inject(OfflineMutationRequestPolicyRegistry).resolve(request);
|
|
5391
|
+
if (plan) {
|
|
5392
|
+
return defer(() => from(plan.prepare())).pipe(map$1((response) => response.clone({ headers: response.headers.set(OFFLINE_RESPONSE_HEADER, 'optimistic') })));
|
|
5393
|
+
}
|
|
5394
|
+
}
|
|
5395
|
+
return transport();
|
|
5396
|
+
};
|
|
5397
|
+
function readNetworkFirst(request, plan, transport, fallback) {
|
|
5398
|
+
return defer(transport).pipe(catchError((error) => fallback.handle(request, error, plan) ?? throwError(() => error)), concatMap((event) => projectReadResponse(event, plan)));
|
|
5399
|
+
}
|
|
5400
|
+
/**
|
|
5401
|
+
* Stale-while-revalidate local-first GET handling.
|
|
5402
|
+
*
|
|
5403
|
+
* @remarks
|
|
5404
|
+
* Starts raw transport and `readLocal()` concurrently at outer subscription,
|
|
5405
|
+
* buffers materialized remote notifications until the local attempt settles,
|
|
5406
|
+
* emits a projected local response first on hit, then drains/projects the
|
|
5407
|
+
* buffered transport. Remote projection begins only after the local decision.
|
|
5408
|
+
*
|
|
5409
|
+
* Consumers must keep the returned observable subscribed through revalidation;
|
|
5410
|
+
* `firstValueFrom` and `take(1)` cancel in-flight transport and suppress
|
|
5411
|
+
* further emissions.
|
|
5412
|
+
*/
|
|
5413
|
+
function readLocalFirst(request, plan, transport, fallback, errorHandler, replicaMutations) {
|
|
5414
|
+
return defer(transport).pipe(materialize(), connect((bufferedTransport$) => resolveLocalAttempt(plan, errorHandler, replicaMutations).pipe(concatMap((localResponse) => localResponse
|
|
5415
|
+
? concat(of(localResponse), drainRemoteAfterLocal(bufferedTransport$, plan))
|
|
5416
|
+
: drainRemoteNetworkFirst(bufferedTransport$, request, plan, fallback))), { connector: () => new ReplaySubject() }));
|
|
5417
|
+
}
|
|
5418
|
+
function resolveLocalAttempt(plan, errorHandler, replicaMutations) {
|
|
5419
|
+
return serializedLocalRead(plan, replicaMutations).pipe(catchError((localError) => {
|
|
5420
|
+
errorHandler.handleError(localError);
|
|
5421
|
+
return of(null);
|
|
5422
|
+
}), concatMap((local) => (local ? tryProjectLocal(local, plan, errorHandler) : of(null))), take(1));
|
|
5423
|
+
}
|
|
5424
|
+
/** Skips a queued local read when its HTTP subscriber leaves before the lane opens. */
|
|
5425
|
+
function serializedLocalRead(plan, replicaMutations) {
|
|
5426
|
+
return new Observable((subscriber) => {
|
|
5427
|
+
let cancelled = false;
|
|
5428
|
+
void replicaMutations
|
|
5429
|
+
.runSerializedRead(async () => (cancelled ? null : plan.readLocal()))
|
|
5430
|
+
.then((response) => {
|
|
5431
|
+
if (cancelled)
|
|
5432
|
+
return;
|
|
5433
|
+
subscriber.next(response);
|
|
5434
|
+
subscriber.complete();
|
|
5435
|
+
}, (error) => {
|
|
5436
|
+
if (!cancelled)
|
|
5437
|
+
subscriber.error(error);
|
|
5438
|
+
});
|
|
5439
|
+
return () => {
|
|
5440
|
+
cancelled = true;
|
|
5441
|
+
};
|
|
5442
|
+
});
|
|
5443
|
+
}
|
|
5444
|
+
function tryProjectLocal(cached, plan, errorHandler) {
|
|
5445
|
+
return emitTaggedLocalResponse(cached, plan).pipe(catchError((error) => {
|
|
5446
|
+
errorHandler.handleError(error);
|
|
5447
|
+
return of(null);
|
|
5448
|
+
}));
|
|
5449
|
+
}
|
|
5450
|
+
function emitTaggedLocalResponse(cached, plan) {
|
|
5451
|
+
return projectReadResponse(cached.clone({ headers: cached.headers.set(OFFLINE_RESPONSE_HEADER, 'local') }), plan);
|
|
5452
|
+
}
|
|
5453
|
+
function drainRemoteAfterLocal(bufferedTransport$, plan) {
|
|
5454
|
+
return bufferedTransport$.pipe(dematerialize(), catchError((error) => (isOfflineFallbackError(error) ? EMPTY : throwError(() => error))), concatMap((event) => projectReadResponse(event, plan)));
|
|
5455
|
+
}
|
|
5456
|
+
function drainRemoteNetworkFirst(bufferedTransport$, request, plan, fallback) {
|
|
5457
|
+
return bufferedTransport$.pipe(dematerialize(), catchError((error) => fallback.handle(request, error, plan) ?? throwError(() => error)), concatMap((event) => projectReadResponse(event, plan)));
|
|
5458
|
+
}
|
|
5459
|
+
function projectReadResponse(event, plan) {
|
|
5460
|
+
if (!(event instanceof HttpResponse) || !plan.projectResponse)
|
|
5461
|
+
return of(event);
|
|
5462
|
+
const source = event.headers.get(OFFLINE_RESPONSE_HEADER) === 'local' ? 'local' : 'remote';
|
|
5463
|
+
return from(plan.projectResponse(event, source)).pipe(map$1((response) => source === 'local' ? response.clone({ headers: response.headers.set(OFFLINE_RESPONSE_HEADER, 'local') }) : response));
|
|
5464
|
+
}
|
|
5465
|
+
function observeTransport(source, network) {
|
|
5466
|
+
return source.pipe(tap({
|
|
5467
|
+
next: (event) => {
|
|
5468
|
+
if (!(event instanceof HttpResponse))
|
|
5469
|
+
return;
|
|
5470
|
+
if (event.headers.get(OFFLINE_RESPONSE_HEADER) === 'local') {
|
|
5471
|
+
network.markApiFailure();
|
|
5472
|
+
return;
|
|
5473
|
+
}
|
|
5474
|
+
network.markApiSuccess();
|
|
5475
|
+
},
|
|
5476
|
+
error: (error) => {
|
|
5477
|
+
if (isOfflineFallbackError(error))
|
|
5478
|
+
network.markApiFailure();
|
|
5479
|
+
},
|
|
5480
|
+
}));
|
|
5481
|
+
}
|
|
5482
|
+
/** Resolves transport failures from the local replica without hiding HTTP errors. */
|
|
5483
|
+
class OfflineRequestFallbackService {
|
|
5484
|
+
#registry = inject(OfflineRequestPolicyRegistry);
|
|
5485
|
+
#errorHandler = inject(ErrorHandler);
|
|
5486
|
+
#replicaMutations = inject(OfflineReplicaMutationCoordinator);
|
|
5487
|
+
handle(request, error, resolvedPlan) {
|
|
5488
|
+
if (request.context.get(OFFLINE_BYPASS) || request.method !== 'GET' || !isOfflineFallbackError(error))
|
|
5489
|
+
return null;
|
|
5490
|
+
const plan = resolvedPlan ?? this.#registry.resolve(request);
|
|
5491
|
+
if (!plan || plan.kind !== 'read')
|
|
5492
|
+
return null;
|
|
5493
|
+
return serializedLocalRead(plan, this.#replicaMutations).pipe(catchError((localError) => {
|
|
5494
|
+
this.#errorHandler.handleError(localError);
|
|
5495
|
+
return throwError(() => error);
|
|
5496
|
+
}), concatMap((cached) => cached ? of(cached.clone({ headers: cached.headers.set(OFFLINE_RESPONSE_HEADER, 'local') })) : throwError(() => error)));
|
|
5497
|
+
}
|
|
5498
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.3", ngImport: i0, type: OfflineRequestFallbackService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
5499
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.1.3", ngImport: i0, type: OfflineRequestFallbackService, providedIn: 'root' }); }
|
|
5500
|
+
}
|
|
5501
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.3", ngImport: i0, type: OfflineRequestFallbackService, decorators: [{
|
|
5502
|
+
type: Injectable,
|
|
5503
|
+
args: [{ providedIn: 'root' }]
|
|
5504
|
+
}] });
|
|
5505
|
+
|
|
5369
5506
|
/** DI token for the native community SQLite driver. */
|
|
5370
5507
|
const COMMUNITY_SQLITE = new InjectionToken('COMMUNITY_SQLITE', {
|
|
5371
5508
|
factory: () => null,
|
|
@@ -6615,6 +6752,26 @@ const READ_CACHE_ONLY_REPLICA_PULLER = {
|
|
|
6615
6752
|
hasMore: false,
|
|
6616
6753
|
}),
|
|
6617
6754
|
};
|
|
6755
|
+
/** Starts one route-scoped offline runtime after product-owned local recovery has completed. */
|
|
6756
|
+
class OfflineRouteInitializerService {
|
|
6757
|
+
#coordinator = inject(OfflineCoordinatorService);
|
|
6758
|
+
#errorHandler = inject(ErrorHandler);
|
|
6759
|
+
#options = inject(OFFLINE_KIT_OPTIONS);
|
|
6760
|
+
#initialization = null;
|
|
6761
|
+
/** Initialize local storage once, then continue transport initialization in the background. */
|
|
6762
|
+
initialize() {
|
|
6763
|
+
return (this.#initialization ??= this.#initialize());
|
|
6764
|
+
}
|
|
6765
|
+
#initialize() {
|
|
6766
|
+
assertSupportedOfflineMode(Capacitor.getPlatform(), this.#options.mode ?? 'synchronized');
|
|
6767
|
+
return initializeOfflineRuntime(this.#coordinator, this.#errorHandler);
|
|
6768
|
+
}
|
|
6769
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.3", ngImport: i0, type: OfflineRouteInitializerService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
6770
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.1.3", ngImport: i0, type: OfflineRouteInitializerService }); }
|
|
6771
|
+
}
|
|
6772
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.3", ngImport: i0, type: OfflineRouteInitializerService, decorators: [{
|
|
6773
|
+
type: Injectable
|
|
6774
|
+
}] });
|
|
6618
6775
|
/**
|
|
6619
6776
|
* Provide the standard scoped offline runtime.
|
|
6620
6777
|
*
|
|
@@ -6627,6 +6784,81 @@ const READ_CACHE_ONLY_REPLICA_PULLER = {
|
|
|
6627
6784
|
* local storage cannot be opened; without it, the app initializer still throws.
|
|
6628
6785
|
*/
|
|
6629
6786
|
function provideOffline(options) {
|
|
6787
|
+
return makeEnvironmentProviders([
|
|
6788
|
+
...offlineConfigurationProviders(options),
|
|
6789
|
+
provideAppInitializer(() => {
|
|
6790
|
+
assertSupportedOfflineMode(Capacitor.getPlatform(), options.mode ?? 'synchronized');
|
|
6791
|
+
return initializeOfflineRuntime(inject(OfflineCoordinatorService), inject(ErrorHandler));
|
|
6792
|
+
}),
|
|
6793
|
+
]);
|
|
6794
|
+
}
|
|
6795
|
+
/**
|
|
6796
|
+
* Provide an isolated offline runtime in a lazy route `EnvironmentInjector`.
|
|
6797
|
+
*
|
|
6798
|
+
* @remarks
|
|
6799
|
+
* This is an additive route-scoped counterpart to {@link provideOffline}. It re-provides every Kit
|
|
6800
|
+
* runtime service so their dependencies resolve from the route injector instead of the application
|
|
6801
|
+
* root. It deliberately does not register an application initializer: the route owns when local
|
|
6802
|
+
* recovery has completed and may then await `OfflineCoordinatorService.initializeLocal()` before
|
|
6803
|
+
* allowing activation. Existing root applications should continue using {@link provideOffline}.
|
|
6804
|
+
*/
|
|
6805
|
+
function provideRouteScopedOffline(options) {
|
|
6806
|
+
return makeEnvironmentProviders([
|
|
6807
|
+
IonicOfflineRepository,
|
|
6808
|
+
SqliteOfflineRepository,
|
|
6809
|
+
OfflineNetworkService,
|
|
6810
|
+
OfflineMutationAdmissionService,
|
|
6811
|
+
OfflineMutationPersistenceService,
|
|
6812
|
+
OfflineSessionService,
|
|
6813
|
+
OfflineReplicaPullService,
|
|
6814
|
+
OfflineReplicaMutationCoordinator,
|
|
6815
|
+
OfflineSyncService,
|
|
6816
|
+
OfflineCoordinatorService,
|
|
6817
|
+
OfflineRequestPolicyRegistry,
|
|
6818
|
+
OfflineMutationRequestPolicyRegistry,
|
|
6819
|
+
OfflineRequestFallbackService,
|
|
6820
|
+
OfflineRouteInitializerService,
|
|
6821
|
+
...routeScopedOptionalDefaults(options),
|
|
6822
|
+
...offlineConfigurationProviders(options),
|
|
6823
|
+
]);
|
|
6824
|
+
}
|
|
6825
|
+
/**
|
|
6826
|
+
* Child-local defaults for every optional offline token the route did not configure.
|
|
6827
|
+
*
|
|
6828
|
+
* @remarks
|
|
6829
|
+
* Without them a parent injector that already ran {@link provideOffline} would leak its own hooks,
|
|
6830
|
+
* projectors, persistence adapter, and policies into the route runtime. Defaults are emitted only
|
|
6831
|
+
* for tokens the route leaves unspecified, so route overrides and multi policies still win.
|
|
6832
|
+
*/
|
|
6833
|
+
function routeScopedOptionalDefaults(options) {
|
|
6834
|
+
const synchronized = options.mode !== 'readCacheOnly';
|
|
6835
|
+
return [
|
|
6836
|
+
...(options.commandHooks ? [] : [{ provide: OFFLINE_COMMAND_HOOKS, useValue: DEFAULT_OFFLINE_COMMAND_HOOKS }]),
|
|
6837
|
+
...(options.replicaProjector ? [] : [{ provide: OFFLINE_REPLICA_PROJECTOR, useValue: null }]),
|
|
6838
|
+
...(synchronized && 'aggregateIntentProjector' in options && options.aggregateIntentProjector
|
|
6839
|
+
? []
|
|
6840
|
+
: [{ provide: OFFLINE_AGGREGATE_INTENT_PROJECTOR, useValue: null }]),
|
|
6841
|
+
...(options.mutationPersistence ? [] : [{ provide: OFFLINE_MUTATION_PERSISTENCE_ADAPTER, useValue: null }]),
|
|
6842
|
+
...(options.requestPolicies.length > 0 ? [] : [{ provide: OFFLINE_REQUEST_POLICIES, useValue: [] }]),
|
|
6843
|
+
...((options.mutationPolicies ?? []).length > 0 ? [] : [{ provide: OFFLINE_MUTATION_REQUEST_POLICIES, useValue: [] }]),
|
|
6844
|
+
];
|
|
6845
|
+
}
|
|
6846
|
+
function initializeOfflineRuntime(coordinator, errorHandler) {
|
|
6847
|
+
const localInitialization = coordinator.initializeLocal();
|
|
6848
|
+
void coordinator.initialize().catch(async (error) => {
|
|
6849
|
+
const localSucceeded = await localInitialization.then(() => true, () => false);
|
|
6850
|
+
if (!localSucceeded)
|
|
6851
|
+
return;
|
|
6852
|
+
try {
|
|
6853
|
+
errorHandler.handleError(error);
|
|
6854
|
+
}
|
|
6855
|
+
catch {
|
|
6856
|
+
// Error reporting must not create an unhandled background rejection.
|
|
6857
|
+
}
|
|
6858
|
+
});
|
|
6859
|
+
return localInitialization;
|
|
6860
|
+
}
|
|
6861
|
+
function offlineConfigurationProviders(options) {
|
|
6630
6862
|
const synchronized = options.mode !== 'readCacheOnly';
|
|
6631
6863
|
const kitOptions = options.databaseEncryption === false
|
|
6632
6864
|
? {
|
|
@@ -6651,7 +6883,7 @@ function provideOffline(options) {
|
|
|
6651
6883
|
mutationPersistence: options.mutationPersistence,
|
|
6652
6884
|
onStorageUnavailable: options.onStorageUnavailable,
|
|
6653
6885
|
};
|
|
6654
|
-
return
|
|
6886
|
+
return [
|
|
6655
6887
|
...(synchronized ? [options.commandExecutor, options.replicaPuller] : []),
|
|
6656
6888
|
{
|
|
6657
6889
|
provide: OFFLINE_KIT_OPTIONS,
|
|
@@ -6692,25 +6924,7 @@ function provideOffline(options) {
|
|
|
6692
6924
|
...options.requestPolicies.flatMap((policy) => provideOfflineRequestPolicy(policy)),
|
|
6693
6925
|
...(options.mutationPolicies ?? []).flatMap((policy) => provideOfflineMutationRequestPolicy(policy)),
|
|
6694
6926
|
...(options.providers ?? []),
|
|
6695
|
-
|
|
6696
|
-
assertSupportedOfflineMode(Capacitor.getPlatform(), options.mode ?? 'synchronized');
|
|
6697
|
-
const coordinator = inject(OfflineCoordinatorService);
|
|
6698
|
-
const errorHandler = inject(ErrorHandler);
|
|
6699
|
-
const localInitialization = coordinator.initializeLocal();
|
|
6700
|
-
void coordinator.initialize().catch(async (error) => {
|
|
6701
|
-
const localSucceeded = await localInitialization.then(() => true, () => false);
|
|
6702
|
-
if (!localSucceeded)
|
|
6703
|
-
return;
|
|
6704
|
-
try {
|
|
6705
|
-
errorHandler.handleError(error);
|
|
6706
|
-
}
|
|
6707
|
-
catch {
|
|
6708
|
-
// Error reporting must not create an unhandled background rejection.
|
|
6709
|
-
}
|
|
6710
|
-
});
|
|
6711
|
-
return localInitialization;
|
|
6712
|
-
}),
|
|
6713
|
-
]);
|
|
6927
|
+
];
|
|
6714
6928
|
}
|
|
6715
6929
|
/** Prevents unsupported multi-tab Web writes from silently losing Outbox state. */
|
|
6716
6930
|
function assertSupportedOfflineMode(platform, mode) {
|
|
@@ -6719,148 +6933,11 @@ function assertSupportedOfflineMode(platform, mode) {
|
|
|
6719
6933
|
}
|
|
6720
6934
|
}
|
|
6721
6935
|
|
|
6722
|
-
const LOCAL_FIRST_MUTATION_METHODS = new Set(['POST', 'PUT', 'PATCH', 'DELETE']);
|
|
6723
|
-
/** Applies product read and local-first mutation policies while observing real API reachability. */
|
|
6724
|
-
const offlineInterceptor = (request, next) => {
|
|
6725
|
-
const network = inject(OfflineNetworkService);
|
|
6726
|
-
const transport = () => observeTransport(next(request), network);
|
|
6727
|
-
if (request.context.get(OFFLINE_BYPASS))
|
|
6728
|
-
return transport();
|
|
6729
|
-
if (request.method === 'GET') {
|
|
6730
|
-
const registry = inject(OfflineRequestPolicyRegistry);
|
|
6731
|
-
const fallback = inject(OfflineRequestFallbackService);
|
|
6732
|
-
const plan = registry.resolve(request);
|
|
6733
|
-
if (!plan)
|
|
6734
|
-
return transport();
|
|
6735
|
-
if (plan.readStrategy === 'local-first') {
|
|
6736
|
-
return readLocalFirst(request, plan, transport, fallback, inject(ErrorHandler), inject(OfflineReplicaMutationCoordinator));
|
|
6737
|
-
}
|
|
6738
|
-
return readNetworkFirst(request, plan, transport, fallback);
|
|
6739
|
-
}
|
|
6740
|
-
if (LOCAL_FIRST_MUTATION_METHODS.has(request.method)) {
|
|
6741
|
-
if (!inject(OFFLINE_MUTATION_PERSISTENCE_ENABLED)())
|
|
6742
|
-
return transport();
|
|
6743
|
-
const plan = inject(OfflineMutationRequestPolicyRegistry).resolve(request);
|
|
6744
|
-
if (plan) {
|
|
6745
|
-
return defer(() => from(plan.prepare())).pipe(map$1((response) => response.clone({ headers: response.headers.set(OFFLINE_RESPONSE_HEADER, 'optimistic') })));
|
|
6746
|
-
}
|
|
6747
|
-
}
|
|
6748
|
-
return transport();
|
|
6749
|
-
};
|
|
6750
|
-
function readNetworkFirst(request, plan, transport, fallback) {
|
|
6751
|
-
return defer(transport).pipe(catchError((error) => fallback.handle(request, error, plan) ?? throwError(() => error)), concatMap((event) => projectReadResponse(event, plan)));
|
|
6752
|
-
}
|
|
6753
|
-
/**
|
|
6754
|
-
* Stale-while-revalidate local-first GET handling.
|
|
6755
|
-
*
|
|
6756
|
-
* @remarks
|
|
6757
|
-
* Starts raw transport and `readLocal()` concurrently at outer subscription,
|
|
6758
|
-
* buffers materialized remote notifications until the local attempt settles,
|
|
6759
|
-
* emits a projected local response first on hit, then drains/projects the
|
|
6760
|
-
* buffered transport. Remote projection begins only after the local decision.
|
|
6761
|
-
*
|
|
6762
|
-
* Consumers must keep the returned observable subscribed through revalidation;
|
|
6763
|
-
* `firstValueFrom` and `take(1)` cancel in-flight transport and suppress
|
|
6764
|
-
* further emissions.
|
|
6765
|
-
*/
|
|
6766
|
-
function readLocalFirst(request, plan, transport, fallback, errorHandler, replicaMutations) {
|
|
6767
|
-
return defer(transport).pipe(materialize(), connect((bufferedTransport$) => resolveLocalAttempt(plan, errorHandler, replicaMutations).pipe(concatMap((localResponse) => localResponse
|
|
6768
|
-
? concat(of(localResponse), drainRemoteAfterLocal(bufferedTransport$, plan))
|
|
6769
|
-
: drainRemoteNetworkFirst(bufferedTransport$, request, plan, fallback))), { connector: () => new ReplaySubject() }));
|
|
6770
|
-
}
|
|
6771
|
-
function resolveLocalAttempt(plan, errorHandler, replicaMutations) {
|
|
6772
|
-
return serializedLocalRead(plan, replicaMutations).pipe(catchError((localError) => {
|
|
6773
|
-
errorHandler.handleError(localError);
|
|
6774
|
-
return of(null);
|
|
6775
|
-
}), concatMap((local) => (local ? tryProjectLocal(local, plan, errorHandler) : of(null))), take(1));
|
|
6776
|
-
}
|
|
6777
|
-
/** Skips a queued local read when its HTTP subscriber leaves before the lane opens. */
|
|
6778
|
-
function serializedLocalRead(plan, replicaMutations) {
|
|
6779
|
-
return new Observable((subscriber) => {
|
|
6780
|
-
let cancelled = false;
|
|
6781
|
-
void replicaMutations
|
|
6782
|
-
.runSerializedRead(async () => (cancelled ? null : plan.readLocal()))
|
|
6783
|
-
.then((response) => {
|
|
6784
|
-
if (cancelled)
|
|
6785
|
-
return;
|
|
6786
|
-
subscriber.next(response);
|
|
6787
|
-
subscriber.complete();
|
|
6788
|
-
}, (error) => {
|
|
6789
|
-
if (!cancelled)
|
|
6790
|
-
subscriber.error(error);
|
|
6791
|
-
});
|
|
6792
|
-
return () => {
|
|
6793
|
-
cancelled = true;
|
|
6794
|
-
};
|
|
6795
|
-
});
|
|
6796
|
-
}
|
|
6797
|
-
function tryProjectLocal(cached, plan, errorHandler) {
|
|
6798
|
-
return emitTaggedLocalResponse(cached, plan).pipe(catchError((error) => {
|
|
6799
|
-
errorHandler.handleError(error);
|
|
6800
|
-
return of(null);
|
|
6801
|
-
}));
|
|
6802
|
-
}
|
|
6803
|
-
function emitTaggedLocalResponse(cached, plan) {
|
|
6804
|
-
return projectReadResponse(cached.clone({ headers: cached.headers.set(OFFLINE_RESPONSE_HEADER, 'local') }), plan);
|
|
6805
|
-
}
|
|
6806
|
-
function drainRemoteAfterLocal(bufferedTransport$, plan) {
|
|
6807
|
-
return bufferedTransport$.pipe(dematerialize(), catchError((error) => (isOfflineFallbackError(error) ? EMPTY : throwError(() => error))), concatMap((event) => projectReadResponse(event, plan)));
|
|
6808
|
-
}
|
|
6809
|
-
function drainRemoteNetworkFirst(bufferedTransport$, request, plan, fallback) {
|
|
6810
|
-
return bufferedTransport$.pipe(dematerialize(), catchError((error) => fallback.handle(request, error, plan) ?? throwError(() => error)), concatMap((event) => projectReadResponse(event, plan)));
|
|
6811
|
-
}
|
|
6812
|
-
function projectReadResponse(event, plan) {
|
|
6813
|
-
if (!(event instanceof HttpResponse) || !plan.projectResponse)
|
|
6814
|
-
return of(event);
|
|
6815
|
-
const source = event.headers.get(OFFLINE_RESPONSE_HEADER) === 'local' ? 'local' : 'remote';
|
|
6816
|
-
return from(plan.projectResponse(event, source)).pipe(map$1((response) => source === 'local' ? response.clone({ headers: response.headers.set(OFFLINE_RESPONSE_HEADER, 'local') }) : response));
|
|
6817
|
-
}
|
|
6818
|
-
function observeTransport(source, network) {
|
|
6819
|
-
return source.pipe(tap({
|
|
6820
|
-
next: (event) => {
|
|
6821
|
-
if (!(event instanceof HttpResponse))
|
|
6822
|
-
return;
|
|
6823
|
-
if (event.headers.get(OFFLINE_RESPONSE_HEADER) === 'local') {
|
|
6824
|
-
network.markApiFailure();
|
|
6825
|
-
return;
|
|
6826
|
-
}
|
|
6827
|
-
network.markApiSuccess();
|
|
6828
|
-
},
|
|
6829
|
-
error: (error) => {
|
|
6830
|
-
if (isOfflineFallbackError(error))
|
|
6831
|
-
network.markApiFailure();
|
|
6832
|
-
},
|
|
6833
|
-
}));
|
|
6834
|
-
}
|
|
6835
|
-
/** Resolves transport failures from the local replica without hiding HTTP errors. */
|
|
6836
|
-
class OfflineRequestFallbackService {
|
|
6837
|
-
#registry = inject(OfflineRequestPolicyRegistry);
|
|
6838
|
-
#errorHandler = inject(ErrorHandler);
|
|
6839
|
-
#replicaMutations = inject(OfflineReplicaMutationCoordinator);
|
|
6840
|
-
handle(request, error, resolvedPlan) {
|
|
6841
|
-
if (request.context.get(OFFLINE_BYPASS) || request.method !== 'GET' || !isOfflineFallbackError(error))
|
|
6842
|
-
return null;
|
|
6843
|
-
const plan = resolvedPlan ?? this.#registry.resolve(request);
|
|
6844
|
-
if (!plan || plan.kind !== 'read')
|
|
6845
|
-
return null;
|
|
6846
|
-
return serializedLocalRead(plan, this.#replicaMutations).pipe(catchError((localError) => {
|
|
6847
|
-
this.#errorHandler.handleError(localError);
|
|
6848
|
-
return throwError(() => error);
|
|
6849
|
-
}), concatMap((cached) => cached ? of(cached.clone({ headers: cached.headers.set(OFFLINE_RESPONSE_HEADER, 'local') })) : throwError(() => error)));
|
|
6850
|
-
}
|
|
6851
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.3", ngImport: i0, type: OfflineRequestFallbackService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
6852
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.1.3", ngImport: i0, type: OfflineRequestFallbackService, providedIn: 'root' }); }
|
|
6853
|
-
}
|
|
6854
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.3", ngImport: i0, type: OfflineRequestFallbackService, decorators: [{
|
|
6855
|
-
type: Injectable,
|
|
6856
|
-
args: [{ providedIn: 'root' }]
|
|
6857
|
-
}] });
|
|
6858
|
-
|
|
6859
6936
|
/** Standard scoped local replica and outbox runtime for offline-capable Ionic applications. */
|
|
6860
6937
|
|
|
6861
6938
|
/**
|
|
6862
6939
|
* Generated bundle index. Do not edit.
|
|
6863
6940
|
*/
|
|
6864
6941
|
|
|
6865
|
-
export { COMMUNITY_SQLITE, DEFAULT_OFFLINE_COMMAND_HOOKS, IonicOfflineRepository, OFFLINE_AGGREGATE_INTENT_PROJECTOR, OFFLINE_BYPASS, OFFLINE_COMMAND_EXECUTOR, OFFLINE_COMMAND_HOOKS, OFFLINE_KIT_OPTIONS, OFFLINE_MUTATION_REQUEST_POLICIES, OFFLINE_REPLICA_PROJECTOR, OFFLINE_REPLICA_PULLER, OFFLINE_REPOSITORY, OFFLINE_REQUEST_POLICIES, OFFLINE_RESPONSE_COMPLETE_HEADER, OFFLINE_RESPONSE_HEADER, OFFLINE_RETRY_RANDOM, OFFLINE_SCHEMA_VERSION, OFFLINE_SYNC_CONTEXT, OfflineCommandInFlightError, OfflineCoordinatorService, OfflineMutationPersistenceDisabledError, OfflineMutationPersistencePendingError, OfflineMutationPersistenceRequiresOnlineError, OfflineMutationPersistenceService, OfflineMutationPolicyConflictError, OfflineMutationProtocolError, OfflineMutationRequestPolicyRegistry, OfflineNetworkService, OfflineOutboxCapacityError, OfflinePayloadValidationError, OfflineReplicaMutationCoordinator, OfflineReplicaPullService, OfflineReplicaSchemaMismatchError, OfflineRequestFallbackService, OfflineRequestPolicyRegistry, OfflineSessionService, OfflineStorageUnavailableError, OfflineSyncService, SqliteOfflineRepository, assertOfflineLocalId, assertOfflineReplicaGeneratedRemoteId, assertOfflineReplicaNaturalKeyBaseline, assertSupportedOfflineMode, booleanColumn, canonicalOfflineCommandIdentity, canonicalOfflinePrincipalId, canonicalOfflineRemoteIdentity, canonicalOfflineReplicaIdentity, canonicalOfflineReplicaRowKey, commandFootprintKeys, commandIdentityFromReplicaIdentity, commandIdentityMatchesReplicaRow, createCommunitySqliteDriver, createOfflineAuthBridge, createRandomOfflineEncryptionKey, datetime, decodeOfflineReplicaValues, defineOfflineReplicaSchema, defineReplicaEntity, encodeOfflineReplicaValues, generatedId, ignored, integer, isOfflineAggregateIntentConflict, isOfflineFallbackError, isOfflineStorageUnavailableError, json, localOnly, migrateOfflineDatabaseEncryption, naturalKey, normalizeOfflineNaturalKey, normalizeOfflineReplicaPullPage, nullable, offlineAggregateIntentMutations, offlineCommandLookupIdentity, offlineCommandTargetFromReplicaRow, offlineCommandWithBaseRevision, offlineGeneratedReplicaIdentity, offlineInterceptor, offlineNaturalKeyFromValues, offlineNaturalReplicaIdentity, offlineReadEmission, offlineReadSource, offlineReplicaRemoteIdentity, offlineRetryDelayMs, offlineSessionManifestAllows, parseOfflineCommandIdentity, parseOfflineMutationEnvelope, parseOfflinePrincipalId, projectOfflineReplicaValues, provideOffline, provideOfflineMutationRequestPolicy, provideOfflineRequestPolicy, real, recoverOfflineLocalReset, replicaAddressFromIdentity, requestOfflineLocalReset, requirePositiveOfflineInteger, selectOfflineRepository, serializeOfflineCommandIdentity, sha256OfflineReplicaSchema, shouldCommitOfflineCollection, supportsSynchronizedOfflineRepository, text };
|
|
6942
|
+
export { COMMUNITY_SQLITE, DEFAULT_OFFLINE_COMMAND_HOOKS, IonicOfflineRepository, OFFLINE_AGGREGATE_INTENT_PROJECTOR, OFFLINE_BYPASS, OFFLINE_COMMAND_EXECUTOR, OFFLINE_COMMAND_HOOKS, OFFLINE_KIT_OPTIONS, OFFLINE_MUTATION_REQUEST_POLICIES, OFFLINE_REPLICA_PROJECTOR, OFFLINE_REPLICA_PULLER, OFFLINE_REPOSITORY, OFFLINE_REQUEST_POLICIES, OFFLINE_RESPONSE_COMPLETE_HEADER, OFFLINE_RESPONSE_HEADER, OFFLINE_RETRY_RANDOM, OFFLINE_SCHEMA_VERSION, OFFLINE_SYNC_CONTEXT, OfflineCommandInFlightError, OfflineCoordinatorService, OfflineMutationPersistenceDisabledError, OfflineMutationPersistencePendingError, OfflineMutationPersistenceRequiresOnlineError, OfflineMutationPersistenceService, OfflineMutationPolicyConflictError, OfflineMutationProtocolError, OfflineMutationRequestPolicyRegistry, OfflineNetworkService, OfflineOutboxCapacityError, OfflinePayloadValidationError, OfflineReplicaMutationCoordinator, OfflineReplicaPullService, OfflineReplicaSchemaMismatchError, OfflineRequestFallbackService, OfflineRequestPolicyRegistry, OfflineRouteInitializerService, OfflineSessionService, OfflineStorageUnavailableError, OfflineSyncService, SqliteOfflineRepository, assertOfflineLocalId, assertOfflineReplicaGeneratedRemoteId, assertOfflineReplicaNaturalKeyBaseline, assertSupportedOfflineMode, booleanColumn, canonicalOfflineCommandIdentity, canonicalOfflinePrincipalId, canonicalOfflineRemoteIdentity, canonicalOfflineReplicaIdentity, canonicalOfflineReplicaRowKey, commandFootprintKeys, commandIdentityFromReplicaIdentity, commandIdentityMatchesReplicaRow, createCommunitySqliteDriver, createOfflineAuthBridge, createRandomOfflineEncryptionKey, datetime, decodeOfflineReplicaValues, defineOfflineReplicaSchema, defineReplicaEntity, encodeOfflineReplicaValues, generatedId, ignored, integer, isOfflineAggregateIntentConflict, isOfflineFallbackError, isOfflineStorageUnavailableError, json, localOnly, migrateOfflineDatabaseEncryption, naturalKey, normalizeOfflineNaturalKey, normalizeOfflineReplicaPullPage, nullable, offlineAggregateIntentMutations, offlineCommandLookupIdentity, offlineCommandTargetFromReplicaRow, offlineCommandWithBaseRevision, offlineGeneratedReplicaIdentity, offlineInterceptor, offlineNaturalKeyFromValues, offlineNaturalReplicaIdentity, offlineReadEmission, offlineReadSource, offlineReplicaRemoteIdentity, offlineRetryDelayMs, offlineSessionManifestAllows, parseOfflineCommandIdentity, parseOfflineMutationEnvelope, parseOfflinePrincipalId, projectOfflineReplicaValues, provideOffline, provideOfflineMutationRequestPolicy, provideOfflineRequestPolicy, provideRouteScopedOffline, real, recoverOfflineLocalReset, replicaAddressFromIdentity, requestOfflineLocalReset, requirePositiveOfflineInteger, selectOfflineRepository, serializeOfflineCommandIdentity, sha256OfflineReplicaSchema, shouldCommitOfflineCollection, supportsSynchronizedOfflineRepository, text };
|
|
6866
6943
|
//# sourceMappingURL=rdlabo-ionic-angular-kit-offline.mjs.map
|