@rdlabo/ionic-angular-kit 21.6.1 → 21.6.2
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.
|
@@ -5,8 +5,8 @@ import { toObservable } from '@angular/core/rxjs-interop';
|
|
|
5
5
|
import { map, distinctUntilChanged } from 'rxjs/operators';
|
|
6
6
|
import { App } from '@capacitor/app';
|
|
7
7
|
import { Network } from '@capacitor/network';
|
|
8
|
-
import { HttpErrorResponse, HttpContextToken, HttpResponse } from '@angular/common/http';
|
|
9
8
|
import { Capacitor } from '@capacitor/core';
|
|
9
|
+
import { HttpErrorResponse, HttpContextToken, HttpResponse } from '@angular/common/http';
|
|
10
10
|
import { defer, from, map as map$1, catchError, throwError, concatMap, materialize, connect, concat, of, ReplaySubject, take, dematerialize, EMPTY, tap } from 'rxjs';
|
|
11
11
|
|
|
12
12
|
const MAX_OFFLINE_NATURAL_KEY_TEXT_BYTES = 1024;
|
|
@@ -2614,182 +2614,59 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.17", ngImpo
|
|
|
2614
2614
|
args: [{ providedIn: 'root' }]
|
|
2615
2615
|
}] });
|
|
2616
2616
|
|
|
2617
|
-
/**
|
|
2618
|
-
|
|
2619
|
-
if (!manifest || manifest.authSubject !== authSubject)
|
|
2620
|
-
return false;
|
|
2621
|
-
return scopeId === undefined || manifest.scopeIds.includes(scopeId);
|
|
2622
|
-
}
|
|
2623
|
-
/** Owns activation and cleanup of the authenticated local-replica boundary. */
|
|
2624
|
-
class OfflineSessionService {
|
|
2617
|
+
/** Raised when a new durable mutation reaches Kit after mutation persistence was closed. */
|
|
2618
|
+
class OfflineMutationPersistenceDisabledError extends Error {
|
|
2625
2619
|
constructor() {
|
|
2626
|
-
|
|
2627
|
-
this
|
|
2628
|
-
this.#initialized = false;
|
|
2629
|
-
this.#localAccessThisRun = false;
|
|
2630
|
-
this.#remoteActivatedThisRun = false;
|
|
2631
|
-
this.activeManifest = this.#activeManifest.asReadonly();
|
|
2620
|
+
super('Offline mutation persistence was disabled before the mutation could be accepted.');
|
|
2621
|
+
this.name = 'OfflineMutationPersistenceDisabledError';
|
|
2632
2622
|
}
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
#
|
|
2637
|
-
#
|
|
2638
|
-
|
|
2639
|
-
|
|
2623
|
+
}
|
|
2624
|
+
/** Product-independent lease gate around every new durable Outbox command. */
|
|
2625
|
+
class OfflineMutationAdmissionService {
|
|
2626
|
+
#options = inject(OFFLINE_KIT_OPTIONS);
|
|
2627
|
+
#accepting = this.#options.mutationPersistence === undefined;
|
|
2628
|
+
#active = 0;
|
|
2629
|
+
#idle = null;
|
|
2630
|
+
#resolveIdle = null;
|
|
2631
|
+
get accepting() {
|
|
2632
|
+
return this.#accepting;
|
|
2633
|
+
}
|
|
2634
|
+
async run(operation) {
|
|
2635
|
+
if (!this.#accepting)
|
|
2636
|
+
throw new OfflineMutationPersistenceDisabledError();
|
|
2637
|
+
this.#active += 1;
|
|
2638
|
+
return new Promise((resolve) => resolve(operation())).finally(() => this.#release());
|
|
2639
|
+
}
|
|
2640
|
+
open() {
|
|
2641
|
+
this.#accepting = true;
|
|
2642
|
+
}
|
|
2643
|
+
async close() {
|
|
2644
|
+
this.#accepting = false;
|
|
2645
|
+
if (this.#active === 0)
|
|
2640
2646
|
return;
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
this.#activeManifest.set(manifest ?? { userId, scopeIds: [], authSubject: null, updatedAt: 0 });
|
|
2646
|
-
}
|
|
2647
|
-
this.#initialized = true;
|
|
2648
|
-
}
|
|
2649
|
-
async activateSession(userId, scopeIds, authSubject, lease) {
|
|
2650
|
-
await this.initialize();
|
|
2651
|
-
if (lease && !lease.isCurrent())
|
|
2652
|
-
return false;
|
|
2653
|
-
const normalizedScopeIds = [...new Set(scopeIds)].sort((a, b) => a.localeCompare(b));
|
|
2654
|
-
const previousUserId = await this.#repository.getLastUserId();
|
|
2655
|
-
if (lease && !lease.isCurrent())
|
|
2656
|
-
return false;
|
|
2657
|
-
let previous = previousUserId === userId ? ((await this.#repository.getSessionManifest(userId)) ?? null) : null;
|
|
2658
|
-
if (lease && !lease.isCurrent())
|
|
2659
|
-
return false;
|
|
2660
|
-
// A changed provider subject is a different person even when the product reuses its numeric id.
|
|
2661
|
-
// This deliberately also clears legacy null -> known subject and known subject -> null transitions.
|
|
2662
|
-
if (previousUserId !== null && (previousUserId !== userId || previous?.authSubject !== authSubject)) {
|
|
2663
|
-
await this.#repository.clearUser(previousUserId);
|
|
2664
|
-
if (lease && !lease.isCurrent())
|
|
2665
|
-
return false;
|
|
2666
|
-
previous = null;
|
|
2667
|
-
}
|
|
2668
|
-
const active = new Set(normalizedScopeIds);
|
|
2669
|
-
await Promise.all((previous?.scopeIds ?? [])
|
|
2670
|
-
.filter((scopeId) => !active.has(scopeId))
|
|
2671
|
-
.map((scopeId) => this.#repository.clearScope({ userId, scopeId })));
|
|
2672
|
-
if (lease && !lease.isCurrent())
|
|
2673
|
-
return false;
|
|
2674
|
-
const manifest = {
|
|
2675
|
-
userId,
|
|
2676
|
-
scopeIds: normalizedScopeIds,
|
|
2677
|
-
authSubject,
|
|
2678
|
-
updatedAt: Date.now(),
|
|
2679
|
-
};
|
|
2680
|
-
await this.#repository.setLastUserId(userId);
|
|
2681
|
-
if (lease && !lease.isCurrent())
|
|
2682
|
-
return false;
|
|
2683
|
-
await this.#repository.putSessionManifest(userId, manifest);
|
|
2684
|
-
if (lease && !lease.isCurrent())
|
|
2685
|
-
return false;
|
|
2686
|
-
this.#activeManifest.set(manifest);
|
|
2687
|
-
this.#localAccessThisRun = true;
|
|
2688
|
-
this.#remoteActivatedThisRun = true;
|
|
2689
|
-
return lease ? true : undefined;
|
|
2690
|
-
}
|
|
2691
|
-
async clearActiveSession() {
|
|
2692
|
-
await this.initialize();
|
|
2693
|
-
const userId = await this.#repository.getLastUserId();
|
|
2694
|
-
if (userId !== null)
|
|
2695
|
-
await this.#repository.clearUser(userId);
|
|
2696
|
-
this.#activeManifest.set(null);
|
|
2697
|
-
this.#localAccessThisRun = false;
|
|
2698
|
-
this.#remoteActivatedThisRun = false;
|
|
2699
|
-
}
|
|
2700
|
-
/** Immediately revoke local and remote runtime access while durable cleanup is pending. */
|
|
2701
|
-
revokeAccess() {
|
|
2702
|
-
this.#localAccessThisRun = false;
|
|
2703
|
-
this.#remoteActivatedThisRun = false;
|
|
2704
|
-
}
|
|
2705
|
-
/** Disable remote pull/replay eligibility while retaining the verified local manifest. */
|
|
2706
|
-
async suspendRemoteSession() {
|
|
2707
|
-
await this.initialize();
|
|
2708
|
-
this.#remoteActivatedThisRun = false;
|
|
2709
|
-
}
|
|
2710
|
-
/**
|
|
2711
|
-
* Returns the persisted identity boundary for local-only route access.
|
|
2712
|
-
*
|
|
2713
|
-
* @remarks
|
|
2714
|
-
* This does not activate the sync context. Call it only after the authentication authority has
|
|
2715
|
-
* been classified as unavailable, never after explicit sign-out or HTTP 401/403. Legacy
|
|
2716
|
-
* manifests without an authentication-provider subject are rejected.
|
|
2717
|
-
*
|
|
2718
|
-
* @param authSubject - A currently known provider subject. When supplied, it must match the
|
|
2719
|
-
* persisted subject.
|
|
2720
|
-
*/
|
|
2721
|
-
async getOfflineAccessManifest(authSubject) {
|
|
2722
|
-
await this.initialize();
|
|
2723
|
-
const manifest = this.#activeManifest();
|
|
2724
|
-
if (!manifest?.authSubject || (authSubject !== undefined && manifest.authSubject !== authSubject)) {
|
|
2725
|
-
return null;
|
|
2647
|
+
if (!this.#idle) {
|
|
2648
|
+
this.#idle = new Promise((resolve) => {
|
|
2649
|
+
this.#resolveIdle = resolve;
|
|
2650
|
+
});
|
|
2726
2651
|
}
|
|
2727
|
-
return
|
|
2728
|
-
}
|
|
2729
|
-
/**
|
|
2730
|
-
* Activates a previously verified manifest for local replica and outbox access only.
|
|
2731
|
-
*
|
|
2732
|
-
* @remarks
|
|
2733
|
-
* This never enables pull or command replay. A later successful remote authentication must call
|
|
2734
|
-
* {@link activateSession} before synchronization can use transport.
|
|
2735
|
-
*
|
|
2736
|
-
* @param authSubject - A currently known provider subject. When supplied, it must match the
|
|
2737
|
-
* persisted subject.
|
|
2738
|
-
*/
|
|
2739
|
-
async activateOfflineSession(authSubject, lease) {
|
|
2740
|
-
const manifest = await this.getOfflineAccessManifest(authSubject);
|
|
2741
|
-
if (lease && !lease.isCurrent())
|
|
2742
|
-
return null;
|
|
2743
|
-
this.#localAccessThisRun = manifest !== null;
|
|
2744
|
-
this.#remoteActivatedThisRun = false;
|
|
2745
|
-
return manifest;
|
|
2746
|
-
}
|
|
2747
|
-
/** Returns the session allowed to use the local replica and append outbox commands. */
|
|
2748
|
-
async getLocalSession() {
|
|
2749
|
-
await this.initialize();
|
|
2750
|
-
return this.#localAccessThisRun ? this.#sessionFromManifest() : null;
|
|
2751
|
-
}
|
|
2752
|
-
/** Returns the remotely authenticated session eligible for pull and command replay. */
|
|
2753
|
-
async getSession() {
|
|
2754
|
-
await this.initialize();
|
|
2755
|
-
return this.#remoteActivatedThisRun ? this.#sessionFromManifest() : null;
|
|
2652
|
+
return this.#idle;
|
|
2756
2653
|
}
|
|
2757
|
-
#
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2654
|
+
#release() {
|
|
2655
|
+
this.#active -= 1;
|
|
2656
|
+
if (this.#active !== 0)
|
|
2657
|
+
return;
|
|
2658
|
+
this.#resolveIdle?.();
|
|
2659
|
+
this.#idle = null;
|
|
2660
|
+
this.#resolveIdle = null;
|
|
2762
2661
|
}
|
|
2763
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.17", ngImport: i0, type:
|
|
2764
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.17", ngImport: i0, type:
|
|
2662
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.17", ngImport: i0, type: OfflineMutationAdmissionService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
2663
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.17", ngImport: i0, type: OfflineMutationAdmissionService, providedIn: 'root' }); }
|
|
2765
2664
|
}
|
|
2766
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.17", ngImport: i0, type:
|
|
2665
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.17", ngImport: i0, type: OfflineMutationAdmissionService, decorators: [{
|
|
2767
2666
|
type: Injectable,
|
|
2768
2667
|
args: [{ providedIn: 'root' }]
|
|
2769
2668
|
}] });
|
|
2770
2669
|
|
|
2771
|
-
/**
|
|
2772
|
-
* Local offline storage could not be opened or migrated without risking data loss.
|
|
2773
|
-
*
|
|
2774
|
-
* Prefer `instanceof` / {@link OfflineStorageUnavailableError.reason} over message text.
|
|
2775
|
-
* The original failure is preserved on {@link Error.cause}. Kit never deletes Outbox or
|
|
2776
|
-
* replica rows in response to this error; recovery is product-owned and explicit.
|
|
2777
|
-
*/
|
|
2778
|
-
class OfflineStorageUnavailableError extends Error {
|
|
2779
|
-
/** Stable machine-readable discriminator for storage initialization failures. */
|
|
2780
|
-
static { this.code = 'OFFLINE_STORAGE_UNAVAILABLE'; }
|
|
2781
|
-
constructor(reason, message, options) {
|
|
2782
|
-
super(message, options);
|
|
2783
|
-
this.reason = reason;
|
|
2784
|
-
this.code = OfflineStorageUnavailableError.code;
|
|
2785
|
-
this.name = 'OfflineStorageUnavailableError';
|
|
2786
|
-
}
|
|
2787
|
-
}
|
|
2788
|
-
/** Narrows an unknown failure to {@link OfflineStorageUnavailableError}. */
|
|
2789
|
-
function isOfflineStorageUnavailableError(error) {
|
|
2790
|
-
return error instanceof OfflineStorageUnavailableError;
|
|
2791
|
-
}
|
|
2792
|
-
|
|
2793
2670
|
/** Raised before persistence when an outbox payload is not losslessly JSON serializable. */
|
|
2794
2671
|
class OfflinePayloadValidationError extends Error {
|
|
2795
2672
|
constructor(message = 'Offline command payload must contain only JSON values') {
|
|
@@ -2845,6 +2722,7 @@ function offlineRetryDelayMs(attempts, random = Math.random) {
|
|
|
2845
2722
|
/** Maintains the optimistic local replica and synchronizes its durable outbox. */
|
|
2846
2723
|
class OfflineSyncService {
|
|
2847
2724
|
#network;
|
|
2725
|
+
#mutationAdmission;
|
|
2848
2726
|
#repository;
|
|
2849
2727
|
#executor;
|
|
2850
2728
|
#context;
|
|
@@ -2873,6 +2751,7 @@ class OfflineSyncService {
|
|
|
2873
2751
|
#lastCommandCreatedAt;
|
|
2874
2752
|
constructor() {
|
|
2875
2753
|
this.#network = inject(OfflineNetworkService);
|
|
2754
|
+
this.#mutationAdmission = inject(OfflineMutationAdmissionService);
|
|
2876
2755
|
this.#repository = inject(OFFLINE_REPOSITORY);
|
|
2877
2756
|
this.#executor = inject(OFFLINE_COMMAND_EXECUTOR);
|
|
2878
2757
|
this.#context = inject(OFFLINE_SYNC_CONTEXT);
|
|
@@ -2986,21 +2865,25 @@ class OfflineSyncService {
|
|
|
2986
2865
|
this.#foregroundScopePolicy = null;
|
|
2987
2866
|
}
|
|
2988
2867
|
enqueue(request, options = {}) {
|
|
2989
|
-
|
|
2990
|
-
|
|
2868
|
+
return this.#mutationAdmission.run(() => {
|
|
2869
|
+
const generation = this.#generation;
|
|
2870
|
+
return this.#serializeReplicaMutation((repository) => this.#enqueue(request, options, generation, undefined, repository));
|
|
2871
|
+
});
|
|
2991
2872
|
}
|
|
2992
2873
|
/**
|
|
2993
2874
|
* Reads, derives, and commits one Outbox command, then rematerializes its
|
|
2994
2875
|
* aggregate from confirmed replica values plus remaining FIFO intents.
|
|
2995
2876
|
*/
|
|
2996
2877
|
enqueuePrepared(prepare, options = {}) {
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
|
|
2878
|
+
return this.#mutationAdmission.run(() => {
|
|
2879
|
+
const generation = this.#generation;
|
|
2880
|
+
return this.#serializeReplicaMutation(async (repository) => {
|
|
2881
|
+
await this.initialize();
|
|
2882
|
+
if (!this.#isCurrent(generation))
|
|
2883
|
+
throw new Error('Offline session changed before prepared enqueue.');
|
|
2884
|
+
const prepared = await prepare(repository);
|
|
2885
|
+
return this.#enqueue(prepared.request, options, generation, undefined, repository);
|
|
2886
|
+
});
|
|
3004
2887
|
});
|
|
3005
2888
|
}
|
|
3006
2889
|
/**
|
|
@@ -3012,13 +2895,15 @@ class OfflineSyncService {
|
|
|
3012
2895
|
* rejected with no durable state change.
|
|
3013
2896
|
*/
|
|
3014
2897
|
enqueuePreparedBatch(prepare, options = {}) {
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
2898
|
+
return this.#mutationAdmission.run(() => {
|
|
2899
|
+
const generation = this.#generation;
|
|
2900
|
+
return this.#serializeReplicaMutation(async (repository) => {
|
|
2901
|
+
await this.initialize();
|
|
2902
|
+
if (!this.#isCurrent(generation))
|
|
2903
|
+
throw new Error('Offline session changed before prepared batch enqueue.');
|
|
2904
|
+
const prepared = await prepare(repository);
|
|
2905
|
+
return this.#enqueuePreparedBatch(prepared, options, generation, repository);
|
|
2906
|
+
});
|
|
3022
2907
|
});
|
|
3023
2908
|
}
|
|
3024
2909
|
/**
|
|
@@ -4323,12 +4208,367 @@ function compareOfflineCommands(left, right) {
|
|
|
4323
4208
|
return left.createdAt - right.createdAt || (left.commandId < right.commandId ? -1 : left.commandId > right.commandId ? 1 : 0);
|
|
4324
4209
|
}
|
|
4325
4210
|
|
|
4211
|
+
/** Raised when disabling requires pending commands to be synchronized while transport is offline. */
|
|
4212
|
+
class OfflineMutationPersistenceRequiresOnlineError extends Error {
|
|
4213
|
+
constructor() {
|
|
4214
|
+
super('Pending offline mutations must be synchronized before persistence can be disabled.');
|
|
4215
|
+
this.name = 'OfflineMutationPersistenceRequiresOnlineError';
|
|
4216
|
+
}
|
|
4217
|
+
}
|
|
4218
|
+
/** Raised when pending commands remain after the disable transition attempted a flush. */
|
|
4219
|
+
class OfflineMutationPersistencePendingError extends Error {
|
|
4220
|
+
constructor(pendingCount) {
|
|
4221
|
+
super('Pending offline mutations remain after synchronization.');
|
|
4222
|
+
this.pendingCount = pendingCount;
|
|
4223
|
+
this.name = 'OfflineMutationPersistencePendingError';
|
|
4224
|
+
}
|
|
4225
|
+
}
|
|
4226
|
+
const settledMutationPersistence = async () => undefined;
|
|
4227
|
+
function invokeMutationPersistence(operation) {
|
|
4228
|
+
return new Promise((resolve) => resolve(operation()));
|
|
4229
|
+
}
|
|
4230
|
+
function reportMutationPersistenceError(errorHandler, error) {
|
|
4231
|
+
try {
|
|
4232
|
+
errorHandler.handleError(error);
|
|
4233
|
+
}
|
|
4234
|
+
catch {
|
|
4235
|
+
// Preference failure already degraded safely to disabled. Telemetry must not stop bootstrap.
|
|
4236
|
+
}
|
|
4237
|
+
}
|
|
4238
|
+
/** Read-only mutation admission signal consumed by the HTTP interceptor. */
|
|
4239
|
+
const OFFLINE_MUTATION_PERSISTENCE_ENABLED = new InjectionToken('OFFLINE_MUTATION_PERSISTENCE_ENABLED', {
|
|
4240
|
+
factory: () => () => true,
|
|
4241
|
+
});
|
|
4242
|
+
/** Product adapter used by Kit to persist the device-local mutation preference. */
|
|
4243
|
+
const OFFLINE_MUTATION_PERSISTENCE_ADAPTER = new InjectionToken('OFFLINE_MUTATION_PERSISTENCE_ADAPTER', { factory: () => null });
|
|
4244
|
+
/** Controls whether Kit accepts new durable mutations while leaving replica reads enabled. */
|
|
4245
|
+
class OfflineMutationPersistenceService {
|
|
4246
|
+
constructor() {
|
|
4247
|
+
this.#options = inject(OFFLINE_KIT_OPTIONS);
|
|
4248
|
+
this.#errorHandler = inject(ErrorHandler);
|
|
4249
|
+
this.#persistence = inject(OFFLINE_MUTATION_PERSISTENCE_ADAPTER);
|
|
4250
|
+
this.#network = inject(OfflineNetworkService);
|
|
4251
|
+
this.#sync = inject(OfflineSyncService);
|
|
4252
|
+
this.#admission = inject(OfflineMutationAdmissionService);
|
|
4253
|
+
this.#configured = this.#options.mode !== 'readCacheOnly' && this.#options.mutationPersistence !== undefined;
|
|
4254
|
+
this.#state = signal(this.#configured ? 'initializing' : 'enabled', ...(ngDevMode ? [{ debugName: "#state" }] : /* istanbul ignore next */ []));
|
|
4255
|
+
this.#initializePromise = null;
|
|
4256
|
+
this.#transitionTail = settledMutationPersistence();
|
|
4257
|
+
this.#transitionRevision = 0;
|
|
4258
|
+
this.#persistedEnabled = !this.#configured;
|
|
4259
|
+
this.#latestTransition = null;
|
|
4260
|
+
/** Whether the product configured a device-local mutation persistence preference. */
|
|
4261
|
+
this.available = this.#configured;
|
|
4262
|
+
/** Whether new durable Outbox mutations are currently accepted. */
|
|
4263
|
+
this.enabled = computed(() => this.#state() === 'enabled', ...(ngDevMode ? [{ debugName: "enabled" }] : /* istanbul ignore next */ []));
|
|
4264
|
+
/** Whether Kit is draining accepted and pending mutations before disabling. */
|
|
4265
|
+
this.changing = computed(() => this.#state() === 'disabling', ...(ngDevMode ? [{ debugName: "changing" }] : /* istanbul ignore next */ []));
|
|
4266
|
+
}
|
|
4267
|
+
#options;
|
|
4268
|
+
#errorHandler;
|
|
4269
|
+
#persistence;
|
|
4270
|
+
#network;
|
|
4271
|
+
#sync;
|
|
4272
|
+
#admission;
|
|
4273
|
+
#configured;
|
|
4274
|
+
#state;
|
|
4275
|
+
#initializePromise;
|
|
4276
|
+
#transitionTail;
|
|
4277
|
+
#transitionRevision;
|
|
4278
|
+
#persistedEnabled;
|
|
4279
|
+
#latestTransition;
|
|
4280
|
+
/** Loads the durable preference before Kit initializes repository-backed services. */
|
|
4281
|
+
async initialize() {
|
|
4282
|
+
if (!this.#configured) {
|
|
4283
|
+
this.#admission.open();
|
|
4284
|
+
return;
|
|
4285
|
+
}
|
|
4286
|
+
await (this.#initializePromise ??= this.#loadInitialPreference());
|
|
4287
|
+
}
|
|
4288
|
+
/**
|
|
4289
|
+
* Enables or disables new durable mutations.
|
|
4290
|
+
*
|
|
4291
|
+
* Disabling closes admission synchronously, waits for already admitted commits,
|
|
4292
|
+
* flushes existing commands, verifies an empty Outbox, and only then persists OFF.
|
|
4293
|
+
*/
|
|
4294
|
+
setEnabled(enabled) {
|
|
4295
|
+
if (!this.#configured)
|
|
4296
|
+
return settledMutationPersistence();
|
|
4297
|
+
const initialization = this.initialize();
|
|
4298
|
+
const latest = this.#latestTransition;
|
|
4299
|
+
if (latest?.enabled === enabled)
|
|
4300
|
+
return latest.promise;
|
|
4301
|
+
if (!latest && ((enabled && this.#state() === 'enabled') || (!enabled && this.#state() === 'disabled'))) {
|
|
4302
|
+
return settledMutationPersistence();
|
|
4303
|
+
}
|
|
4304
|
+
const revision = ++this.#transitionRevision;
|
|
4305
|
+
if (!enabled) {
|
|
4306
|
+
this.#state.set('disabling');
|
|
4307
|
+
void this.#admission.close();
|
|
4308
|
+
}
|
|
4309
|
+
const transition = this.#transitionTail.then(() => initialization).then(() => this.#applyTransition(enabled, revision));
|
|
4310
|
+
this.#transitionTail = transition.catch(() => undefined);
|
|
4311
|
+
const promise = transition.finally(() => {
|
|
4312
|
+
if (this.#latestTransition?.revision === revision)
|
|
4313
|
+
this.#latestTransition = null;
|
|
4314
|
+
});
|
|
4315
|
+
this.#latestTransition = { enabled, promise, revision };
|
|
4316
|
+
return promise;
|
|
4317
|
+
}
|
|
4318
|
+
async #loadInitialPreference() {
|
|
4319
|
+
const persistence = this.#requiredPersistence();
|
|
4320
|
+
return invokeMutationPersistence(() => persistence.loadEnabled()).then((stored) => {
|
|
4321
|
+
this.#persistedEnabled = stored ?? this.#options.mutationPersistence?.defaultEnabled ?? true;
|
|
4322
|
+
if (this.#transitionRevision === 0) {
|
|
4323
|
+
this.#state.set(this.#persistedEnabled ? 'enabled' : 'disabled');
|
|
4324
|
+
if (this.#persistedEnabled)
|
|
4325
|
+
this.#admission.open();
|
|
4326
|
+
}
|
|
4327
|
+
}, async (error) => {
|
|
4328
|
+
this.#persistedEnabled = false;
|
|
4329
|
+
if (this.#transitionRevision === 0)
|
|
4330
|
+
this.#state.set('disabled');
|
|
4331
|
+
await this.#admission.close();
|
|
4332
|
+
reportMutationPersistenceError(this.#errorHandler, error);
|
|
4333
|
+
});
|
|
4334
|
+
}
|
|
4335
|
+
#applyTransition(enabled, revision) {
|
|
4336
|
+
if (revision !== this.#transitionRevision)
|
|
4337
|
+
return settledMutationPersistence();
|
|
4338
|
+
const transition = enabled ? this.#enable(revision) : this.#disable(revision);
|
|
4339
|
+
return transition.catch((error) => {
|
|
4340
|
+
if (revision === this.#transitionRevision) {
|
|
4341
|
+
this.#state.set(this.#persistedEnabled ? 'enabled' : 'disabled');
|
|
4342
|
+
if (this.#persistedEnabled)
|
|
4343
|
+
this.#admission.open();
|
|
4344
|
+
}
|
|
4345
|
+
return Promise.reject(error);
|
|
4346
|
+
});
|
|
4347
|
+
}
|
|
4348
|
+
async #enable(revision) {
|
|
4349
|
+
await this.#requiredPersistence().saveEnabled(true);
|
|
4350
|
+
this.#persistedEnabled = true;
|
|
4351
|
+
if (revision !== this.#transitionRevision)
|
|
4352
|
+
return;
|
|
4353
|
+
this.#state.set('enabled');
|
|
4354
|
+
this.#admission.open();
|
|
4355
|
+
}
|
|
4356
|
+
async #disable(revision) {
|
|
4357
|
+
await this.#admission.close();
|
|
4358
|
+
if (revision !== this.#transitionRevision)
|
|
4359
|
+
return;
|
|
4360
|
+
const pendingBeforeFlush = this.#sync.pendingCount();
|
|
4361
|
+
if (pendingBeforeFlush > 0) {
|
|
4362
|
+
if (this.#network.state() === 'offline')
|
|
4363
|
+
throw new OfflineMutationPersistenceRequiresOnlineError();
|
|
4364
|
+
await this.#sync.flush();
|
|
4365
|
+
}
|
|
4366
|
+
if (revision !== this.#transitionRevision)
|
|
4367
|
+
return;
|
|
4368
|
+
const pendingCount = this.#sync.pendingCount();
|
|
4369
|
+
if (pendingCount > 0)
|
|
4370
|
+
throw new OfflineMutationPersistencePendingError(pendingCount);
|
|
4371
|
+
await this.#requiredPersistence().saveEnabled(false);
|
|
4372
|
+
this.#persistedEnabled = false;
|
|
4373
|
+
if (revision === this.#transitionRevision)
|
|
4374
|
+
this.#state.set('disabled');
|
|
4375
|
+
}
|
|
4376
|
+
#requiredPersistence() {
|
|
4377
|
+
if (!this.#persistence)
|
|
4378
|
+
throw new Error('Offline mutation persistence adapter is not provided.');
|
|
4379
|
+
return this.#persistence;
|
|
4380
|
+
}
|
|
4381
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.17", ngImport: i0, type: OfflineMutationPersistenceService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
4382
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.17", ngImport: i0, type: OfflineMutationPersistenceService, providedIn: 'root' }); }
|
|
4383
|
+
}
|
|
4384
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.17", ngImport: i0, type: OfflineMutationPersistenceService, decorators: [{
|
|
4385
|
+
type: Injectable,
|
|
4386
|
+
args: [{ providedIn: 'root' }]
|
|
4387
|
+
}] });
|
|
4388
|
+
|
|
4389
|
+
/** Checks the authenticated subject and optional scope against one persisted session boundary. */
|
|
4390
|
+
function offlineSessionManifestAllows(manifest, authSubject, scopeId) {
|
|
4391
|
+
if (!manifest || manifest.authSubject !== authSubject)
|
|
4392
|
+
return false;
|
|
4393
|
+
return scopeId === undefined || manifest.scopeIds.includes(scopeId);
|
|
4394
|
+
}
|
|
4395
|
+
/** Owns activation and cleanup of the authenticated local-replica boundary. */
|
|
4396
|
+
class OfflineSessionService {
|
|
4397
|
+
constructor() {
|
|
4398
|
+
this.#repository = inject(OFFLINE_REPOSITORY);
|
|
4399
|
+
this.#activeManifest = signal(null, ...(ngDevMode ? [{ debugName: "#activeManifest" }] : /* istanbul ignore next */ []));
|
|
4400
|
+
this.#initialized = false;
|
|
4401
|
+
this.#localAccessThisRun = false;
|
|
4402
|
+
this.#remoteActivatedThisRun = false;
|
|
4403
|
+
this.activeManifest = this.#activeManifest.asReadonly();
|
|
4404
|
+
}
|
|
4405
|
+
#repository;
|
|
4406
|
+
#activeManifest;
|
|
4407
|
+
#initialized;
|
|
4408
|
+
#localAccessThisRun;
|
|
4409
|
+
#remoteActivatedThisRun;
|
|
4410
|
+
async initialize() {
|
|
4411
|
+
if (this.#initialized)
|
|
4412
|
+
return;
|
|
4413
|
+
await this.#repository.initialize();
|
|
4414
|
+
const userId = await this.#repository.getLastUserId();
|
|
4415
|
+
if (userId !== null) {
|
|
4416
|
+
const manifest = await this.#repository.getSessionManifest(userId);
|
|
4417
|
+
this.#activeManifest.set(manifest ?? { userId, scopeIds: [], authSubject: null, updatedAt: 0 });
|
|
4418
|
+
}
|
|
4419
|
+
this.#initialized = true;
|
|
4420
|
+
}
|
|
4421
|
+
async activateSession(userId, scopeIds, authSubject, lease) {
|
|
4422
|
+
await this.initialize();
|
|
4423
|
+
if (lease && !lease.isCurrent())
|
|
4424
|
+
return false;
|
|
4425
|
+
const normalizedScopeIds = [...new Set(scopeIds)].sort((a, b) => a.localeCompare(b));
|
|
4426
|
+
const previousUserId = await this.#repository.getLastUserId();
|
|
4427
|
+
if (lease && !lease.isCurrent())
|
|
4428
|
+
return false;
|
|
4429
|
+
let previous = previousUserId === userId ? ((await this.#repository.getSessionManifest(userId)) ?? null) : null;
|
|
4430
|
+
if (lease && !lease.isCurrent())
|
|
4431
|
+
return false;
|
|
4432
|
+
// A changed provider subject is a different person even when the product reuses its numeric id.
|
|
4433
|
+
// This deliberately also clears legacy null -> known subject and known subject -> null transitions.
|
|
4434
|
+
if (previousUserId !== null && (previousUserId !== userId || previous?.authSubject !== authSubject)) {
|
|
4435
|
+
await this.#repository.clearUser(previousUserId);
|
|
4436
|
+
if (lease && !lease.isCurrent())
|
|
4437
|
+
return false;
|
|
4438
|
+
previous = null;
|
|
4439
|
+
}
|
|
4440
|
+
const active = new Set(normalizedScopeIds);
|
|
4441
|
+
await Promise.all((previous?.scopeIds ?? [])
|
|
4442
|
+
.filter((scopeId) => !active.has(scopeId))
|
|
4443
|
+
.map((scopeId) => this.#repository.clearScope({ userId, scopeId })));
|
|
4444
|
+
if (lease && !lease.isCurrent())
|
|
4445
|
+
return false;
|
|
4446
|
+
const manifest = {
|
|
4447
|
+
userId,
|
|
4448
|
+
scopeIds: normalizedScopeIds,
|
|
4449
|
+
authSubject,
|
|
4450
|
+
updatedAt: Date.now(),
|
|
4451
|
+
};
|
|
4452
|
+
await this.#repository.setLastUserId(userId);
|
|
4453
|
+
if (lease && !lease.isCurrent())
|
|
4454
|
+
return false;
|
|
4455
|
+
await this.#repository.putSessionManifest(userId, manifest);
|
|
4456
|
+
if (lease && !lease.isCurrent())
|
|
4457
|
+
return false;
|
|
4458
|
+
this.#activeManifest.set(manifest);
|
|
4459
|
+
this.#localAccessThisRun = true;
|
|
4460
|
+
this.#remoteActivatedThisRun = true;
|
|
4461
|
+
return lease ? true : undefined;
|
|
4462
|
+
}
|
|
4463
|
+
async clearActiveSession() {
|
|
4464
|
+
await this.initialize();
|
|
4465
|
+
const userId = await this.#repository.getLastUserId();
|
|
4466
|
+
if (userId !== null)
|
|
4467
|
+
await this.#repository.clearUser(userId);
|
|
4468
|
+
this.#activeManifest.set(null);
|
|
4469
|
+
this.#localAccessThisRun = false;
|
|
4470
|
+
this.#remoteActivatedThisRun = false;
|
|
4471
|
+
}
|
|
4472
|
+
/** Immediately revoke local and remote runtime access while durable cleanup is pending. */
|
|
4473
|
+
revokeAccess() {
|
|
4474
|
+
this.#localAccessThisRun = false;
|
|
4475
|
+
this.#remoteActivatedThisRun = false;
|
|
4476
|
+
}
|
|
4477
|
+
/** Disable remote pull/replay eligibility while retaining the verified local manifest. */
|
|
4478
|
+
async suspendRemoteSession() {
|
|
4479
|
+
await this.initialize();
|
|
4480
|
+
this.#remoteActivatedThisRun = false;
|
|
4481
|
+
}
|
|
4482
|
+
/**
|
|
4483
|
+
* Returns the persisted identity boundary for local-only route access.
|
|
4484
|
+
*
|
|
4485
|
+
* @remarks
|
|
4486
|
+
* This does not activate the sync context. Call it only after the authentication authority has
|
|
4487
|
+
* been classified as unavailable, never after explicit sign-out or HTTP 401/403. Legacy
|
|
4488
|
+
* manifests without an authentication-provider subject are rejected.
|
|
4489
|
+
*
|
|
4490
|
+
* @param authSubject - A currently known provider subject. When supplied, it must match the
|
|
4491
|
+
* persisted subject.
|
|
4492
|
+
*/
|
|
4493
|
+
async getOfflineAccessManifest(authSubject) {
|
|
4494
|
+
await this.initialize();
|
|
4495
|
+
const manifest = this.#activeManifest();
|
|
4496
|
+
if (!manifest?.authSubject || (authSubject !== undefined && manifest.authSubject !== authSubject)) {
|
|
4497
|
+
return null;
|
|
4498
|
+
}
|
|
4499
|
+
return { ...manifest, scopeIds: [...manifest.scopeIds] };
|
|
4500
|
+
}
|
|
4501
|
+
/**
|
|
4502
|
+
* Activates a previously verified manifest for local replica and outbox access only.
|
|
4503
|
+
*
|
|
4504
|
+
* @remarks
|
|
4505
|
+
* This never enables pull or command replay. A later successful remote authentication must call
|
|
4506
|
+
* {@link activateSession} before synchronization can use transport.
|
|
4507
|
+
*
|
|
4508
|
+
* @param authSubject - A currently known provider subject. When supplied, it must match the
|
|
4509
|
+
* persisted subject.
|
|
4510
|
+
*/
|
|
4511
|
+
async activateOfflineSession(authSubject, lease) {
|
|
4512
|
+
const manifest = await this.getOfflineAccessManifest(authSubject);
|
|
4513
|
+
if (lease && !lease.isCurrent())
|
|
4514
|
+
return null;
|
|
4515
|
+
this.#localAccessThisRun = manifest !== null;
|
|
4516
|
+
this.#remoteActivatedThisRun = false;
|
|
4517
|
+
return manifest;
|
|
4518
|
+
}
|
|
4519
|
+
/** Returns the session allowed to use the local replica and append outbox commands. */
|
|
4520
|
+
async getLocalSession() {
|
|
4521
|
+
await this.initialize();
|
|
4522
|
+
return this.#localAccessThisRun ? this.#sessionFromManifest() : null;
|
|
4523
|
+
}
|
|
4524
|
+
/** Returns the remotely authenticated session eligible for pull and command replay. */
|
|
4525
|
+
async getSession() {
|
|
4526
|
+
await this.initialize();
|
|
4527
|
+
return this.#remoteActivatedThisRun ? this.#sessionFromManifest() : null;
|
|
4528
|
+
}
|
|
4529
|
+
#sessionFromManifest() {
|
|
4530
|
+
const manifest = this.#activeManifest();
|
|
4531
|
+
return manifest
|
|
4532
|
+
? { userId: manifest.userId, scopes: manifest.scopeIds.map((scopeId) => ({ userId: manifest.userId, scopeId })) }
|
|
4533
|
+
: null;
|
|
4534
|
+
}
|
|
4535
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.17", ngImport: i0, type: OfflineSessionService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
4536
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.17", ngImport: i0, type: OfflineSessionService, providedIn: 'root' }); }
|
|
4537
|
+
}
|
|
4538
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.17", ngImport: i0, type: OfflineSessionService, decorators: [{
|
|
4539
|
+
type: Injectable,
|
|
4540
|
+
args: [{ providedIn: 'root' }]
|
|
4541
|
+
}] });
|
|
4542
|
+
|
|
4543
|
+
/**
|
|
4544
|
+
* Local offline storage could not be opened or migrated without risking data loss.
|
|
4545
|
+
*
|
|
4546
|
+
* Prefer `instanceof` / {@link OfflineStorageUnavailableError.reason} over message text.
|
|
4547
|
+
* The original failure is preserved on {@link Error.cause}. Kit never deletes Outbox or
|
|
4548
|
+
* replica rows in response to this error; recovery is product-owned and explicit.
|
|
4549
|
+
*/
|
|
4550
|
+
class OfflineStorageUnavailableError extends Error {
|
|
4551
|
+
/** Stable machine-readable discriminator for storage initialization failures. */
|
|
4552
|
+
static { this.code = 'OFFLINE_STORAGE_UNAVAILABLE'; }
|
|
4553
|
+
constructor(reason, message, options) {
|
|
4554
|
+
super(message, options);
|
|
4555
|
+
this.reason = reason;
|
|
4556
|
+
this.code = OfflineStorageUnavailableError.code;
|
|
4557
|
+
this.name = 'OfflineStorageUnavailableError';
|
|
4558
|
+
}
|
|
4559
|
+
}
|
|
4560
|
+
/** Narrows an unknown failure to {@link OfflineStorageUnavailableError}. */
|
|
4561
|
+
function isOfflineStorageUnavailableError(error) {
|
|
4562
|
+
return error instanceof OfflineStorageUnavailableError;
|
|
4563
|
+
}
|
|
4564
|
+
|
|
4326
4565
|
const settledTransition = async () => undefined;
|
|
4327
4566
|
/** Coordinates local persistence, session boundaries, network state, and outbox synchronization. */
|
|
4328
4567
|
class OfflineCoordinatorService {
|
|
4329
4568
|
constructor() {
|
|
4330
4569
|
this.#repository = inject(OFFLINE_REPOSITORY);
|
|
4331
4570
|
this.#network = inject(OfflineNetworkService);
|
|
4571
|
+
this.#mutationPersistence = inject(OfflineMutationPersistenceService);
|
|
4332
4572
|
this.#sync = inject(OfflineSyncService);
|
|
4333
4573
|
this.#session = inject(OfflineSessionService);
|
|
4334
4574
|
this.#options = inject(OFFLINE_KIT_OPTIONS);
|
|
@@ -4351,9 +4591,12 @@ class OfflineCoordinatorService {
|
|
|
4351
4591
|
this.syncState = this.#sync.syncState;
|
|
4352
4592
|
this.pendingCount = this.#sync.pendingCount;
|
|
4353
4593
|
this.conflicts = this.#sync.conflicts;
|
|
4594
|
+
/** Device-local control for accepting new durable Outbox mutations. */
|
|
4595
|
+
this.mutationPersistence = this.#mutationPersistence;
|
|
4354
4596
|
}
|
|
4355
4597
|
#repository;
|
|
4356
4598
|
#network;
|
|
4599
|
+
#mutationPersistence;
|
|
4357
4600
|
#sync;
|
|
4358
4601
|
#session;
|
|
4359
4602
|
#options;
|
|
@@ -4368,6 +4611,7 @@ class OfflineCoordinatorService {
|
|
|
4368
4611
|
* resolves with {@link storageState} `unavailable` and skips session/sync initialization.
|
|
4369
4612
|
*/
|
|
4370
4613
|
async initialize() {
|
|
4614
|
+
await this.#mutationPersistence.initialize();
|
|
4371
4615
|
const networkReady = this.#network.initialize();
|
|
4372
4616
|
const initializeRepository = async () => this.#repository.initialize();
|
|
4373
4617
|
const repositoryReady = await initializeRepository().then(() => true, async (error) => {
|
|
@@ -4599,6 +4843,57 @@ function assertOfflineRemoteIdentity(identity) {
|
|
|
4599
4843
|
}
|
|
4600
4844
|
}
|
|
4601
4845
|
|
|
4846
|
+
const COMMUNITY_SQLITE_ENCRYPTED = true;
|
|
4847
|
+
const COMMUNITY_SQLITE_MODE = 'secret';
|
|
4848
|
+
const COMMUNITY_SQLITE_VERSION = 1;
|
|
4849
|
+
const COMMUNITY_SQLITE_READONLY = false;
|
|
4850
|
+
|
|
4851
|
+
const OFFLINE_LOCAL_RESET_REQUESTED = 'requested';
|
|
4852
|
+
/** Persists an explicit destructive reset request, then reloads into a cold bootstrap. */
|
|
4853
|
+
async function requestOfflineLocalReset(options) {
|
|
4854
|
+
await options.markerStore.set({ key: options.markerKey, value: OFFLINE_LOCAL_RESET_REQUESTED });
|
|
4855
|
+
const reloadTarget = options.reloadTarget ?? globalThis.location;
|
|
4856
|
+
reloadTarget.reload();
|
|
4857
|
+
}
|
|
4858
|
+
/**
|
|
4859
|
+
* Recovers an explicit reset request before Angular and Kit open native SQLite.
|
|
4860
|
+
*
|
|
4861
|
+
* The marker is removed only after the Kit database and every product cleanup succeed.
|
|
4862
|
+
* Kit never invokes this helper automatically in response to a storage failure.
|
|
4863
|
+
*/
|
|
4864
|
+
async function recoverOfflineLocalReset(options) {
|
|
4865
|
+
if (!(options.nativePlatform ?? Capacitor.isNativePlatform()))
|
|
4866
|
+
return false;
|
|
4867
|
+
const marker = await options.markerStore.get({ key: options.markerKey });
|
|
4868
|
+
if (marker.value !== OFFLINE_LOCAL_RESET_REQUESTED)
|
|
4869
|
+
return false;
|
|
4870
|
+
await options.sqliteConnection.checkConnectionsConsistency();
|
|
4871
|
+
for (const databaseName of new Set(options.kitCompatibleDatabaseNames)) {
|
|
4872
|
+
const exists = await options.sqliteConnection.isDatabase(databaseName);
|
|
4873
|
+
if (exists.result) {
|
|
4874
|
+
const connection = await options.sqliteConnection.createConnection(databaseName, COMMUNITY_SQLITE_ENCRYPTED, COMMUNITY_SQLITE_MODE, COMMUNITY_SQLITE_VERSION, COMMUNITY_SQLITE_READONLY);
|
|
4875
|
+
await deleteAndCloseOfflineDatabase(options.sqliteConnection, databaseName, connection);
|
|
4876
|
+
}
|
|
4877
|
+
}
|
|
4878
|
+
await options.additionalCleanup?.();
|
|
4879
|
+
await options.markerStore.remove({ key: options.markerKey });
|
|
4880
|
+
return true;
|
|
4881
|
+
}
|
|
4882
|
+
async function settleOfflineResetOperation(operation) {
|
|
4883
|
+
return new Promise((resolve) => resolve(operation())).then(() => ({ ok: true }), (error) => ({ ok: false, error }));
|
|
4884
|
+
}
|
|
4885
|
+
async function deleteAndCloseOfflineDatabase(sqliteConnection, databaseName, connection) {
|
|
4886
|
+
const deletion = await settleOfflineResetOperation(() => connection.delete());
|
|
4887
|
+
const closing = await settleOfflineResetOperation(() => sqliteConnection.closeConnection(databaseName, COMMUNITY_SQLITE_READONLY));
|
|
4888
|
+
if (!deletion.ok && !closing.ok) {
|
|
4889
|
+
throw new AggregateError([deletion.error, closing.error], `Offline database ${databaseName} delete and close both failed.`);
|
|
4890
|
+
}
|
|
4891
|
+
if (!deletion.ok)
|
|
4892
|
+
throw deletion.error;
|
|
4893
|
+
if (!closing.ok)
|
|
4894
|
+
throw closing.error;
|
|
4895
|
+
}
|
|
4896
|
+
|
|
4602
4897
|
/**
|
|
4603
4898
|
* A successful HTTP response that violates the offline mutation protocol.
|
|
4604
4899
|
*
|
|
@@ -4773,7 +5068,7 @@ function createCommunitySqliteDriver(connection) {
|
|
|
4773
5068
|
throw new Error('Native offline storage requires a non-empty encryption key on first open');
|
|
4774
5069
|
await connection.setEncryptionSecret(encryptionKey);
|
|
4775
5070
|
}
|
|
4776
|
-
const value = await connection.createConnection(databaseName,
|
|
5071
|
+
const value = await connection.createConnection(databaseName, COMMUNITY_SQLITE_ENCRYPTED, COMMUNITY_SQLITE_MODE, COMMUNITY_SQLITE_VERSION, COMMUNITY_SQLITE_READONLY);
|
|
4777
5072
|
await value.open();
|
|
4778
5073
|
databases.set(databaseName, value);
|
|
4779
5074
|
return { databaseId: databaseName };
|
|
@@ -5848,6 +6143,7 @@ function provideOffline(options) {
|
|
|
5848
6143
|
replicaSchema: options.replicaSchema,
|
|
5849
6144
|
wireProtocol: options.wireProtocol,
|
|
5850
6145
|
outboxLimits: options.outboxLimits,
|
|
6146
|
+
mutationPersistence: options.mutationPersistence,
|
|
5851
6147
|
onStorageUnavailable: options.onStorageUnavailable,
|
|
5852
6148
|
},
|
|
5853
6149
|
},
|
|
@@ -5859,6 +6155,16 @@ function provideOffline(options) {
|
|
|
5859
6155
|
provide: OFFLINE_REPOSITORY,
|
|
5860
6156
|
useFactory: () => selectOfflineRepository(Capacitor.getPlatform(), inject(IonicOfflineRepository), inject(SqliteOfflineRepository)),
|
|
5861
6157
|
},
|
|
6158
|
+
{
|
|
6159
|
+
provide: OFFLINE_MUTATION_PERSISTENCE_ENABLED,
|
|
6160
|
+
useFactory: () => inject(OfflineMutationPersistenceService).enabled,
|
|
6161
|
+
},
|
|
6162
|
+
...(options.mutationPersistence
|
|
6163
|
+
? [
|
|
6164
|
+
options.mutationPersistence.adapter,
|
|
6165
|
+
{ provide: OFFLINE_MUTATION_PERSISTENCE_ADAPTER, useExisting: options.mutationPersistence.adapter },
|
|
6166
|
+
]
|
|
6167
|
+
: []),
|
|
5862
6168
|
{ provide: OFFLINE_SYNC_CONTEXT, useExisting: OfflineSessionService },
|
|
5863
6169
|
synchronized
|
|
5864
6170
|
? { provide: OFFLINE_COMMAND_EXECUTOR, useExisting: options.commandExecutor }
|
|
@@ -5908,6 +6214,8 @@ const offlineInterceptor = (request, next) => {
|
|
|
5908
6214
|
return readNetworkFirst(request, plan, transport, fallback);
|
|
5909
6215
|
}
|
|
5910
6216
|
if (LOCAL_FIRST_MUTATION_METHODS.has(request.method)) {
|
|
6217
|
+
if (!inject(OFFLINE_MUTATION_PERSISTENCE_ENABLED)())
|
|
6218
|
+
return transport();
|
|
5911
6219
|
const plan = inject(OfflineMutationRequestPolicyRegistry).resolve(request);
|
|
5912
6220
|
if (plan) {
|
|
5913
6221
|
return defer(() => from(plan.prepare())).pipe(map$1((response) => response.clone({ headers: response.headers.set(OFFLINE_RESPONSE_HEADER, 'optimistic') })));
|
|
@@ -6009,5 +6317,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.17", ngImpo
|
|
|
6009
6317
|
* Generated bundle index. Do not edit.
|
|
6010
6318
|
*/
|
|
6011
6319
|
|
|
6012
|
-
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_HEADER, OFFLINE_RETRY_RANDOM, OFFLINE_SCHEMA_VERSION, OFFLINE_SYNC_CONTEXT, OfflineCommandInFlightError, OfflineCoordinatorService, 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, naturalKey, normalizeOfflineNaturalKey, normalizeOfflineReplicaPullPage, nullable, offlineAggregateIntentMutations, offlineCommandLookupIdentity, offlineCommandTargetFromReplicaRow, offlineCommandWithBaseRevision, offlineGeneratedReplicaIdentity, offlineInterceptor, offlineNaturalKeyFromValues, offlineNaturalReplicaIdentity, offlineReplicaRemoteIdentity, offlineRetryDelayMs, offlineSessionManifestAllows, parseOfflineCommandIdentity, parseOfflineMutationEnvelope, parseOfflinePrincipalId, projectOfflineReplicaValues, provideOffline, provideOfflineMutationRequestPolicy, provideOfflineRequestPolicy, real, replicaAddressFromIdentity, requirePositiveOfflineInteger, selectOfflineRepository, serializeOfflineCommandIdentity, sha256OfflineReplicaSchema, supportsSynchronizedOfflineRepository, text };
|
|
6320
|
+
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_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, naturalKey, normalizeOfflineNaturalKey, normalizeOfflineReplicaPullPage, nullable, offlineAggregateIntentMutations, offlineCommandLookupIdentity, offlineCommandTargetFromReplicaRow, offlineCommandWithBaseRevision, offlineGeneratedReplicaIdentity, offlineInterceptor, offlineNaturalKeyFromValues, offlineNaturalReplicaIdentity, offlineReplicaRemoteIdentity, offlineRetryDelayMs, offlineSessionManifestAllows, parseOfflineCommandIdentity, parseOfflineMutationEnvelope, parseOfflinePrincipalId, projectOfflineReplicaValues, provideOffline, provideOfflineMutationRequestPolicy, provideOfflineRequestPolicy, real, recoverOfflineLocalReset, replicaAddressFromIdentity, requestOfflineLocalReset, requirePositiveOfflineInteger, selectOfflineRepository, serializeOfflineCommandIdentity, sha256OfflineReplicaSchema, supportsSynchronizedOfflineRepository, text };
|
|
6013
6321
|
//# sourceMappingURL=rdlabo-ionic-angular-kit-offline.mjs.map
|