@rdlabo/ionic-angular-kit 22.0.0-beta.pr97.shaea83d9a904af → 22.0.0-beta.pr98.sha5e7e3312b58f
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,
|
|
10
|
+
import { defer, from, map as map$1, concatMap, EMPTY, of, catchError, throwError, materialize, connect, concat, ReplaySubject, filter, NEVER, race, take, Observable, dematerialize, 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_]*$/;
|
|
@@ -2851,6 +2851,15 @@ class OfflinePayloadValidationError extends Error {
|
|
|
2851
2851
|
this.name = 'OfflinePayloadValidationError';
|
|
2852
2852
|
}
|
|
2853
2853
|
}
|
|
2854
|
+
/** A foreground durable-command send reached a terminal server-side state. */
|
|
2855
|
+
class OfflineImmediateCommandRejectedError extends Error {
|
|
2856
|
+
constructor(state, code) {
|
|
2857
|
+
super(`Immediate offline command delivery ended in ${state}${code ? ` (${code})` : ''}.`);
|
|
2858
|
+
this.state = state;
|
|
2859
|
+
this.code = code;
|
|
2860
|
+
this.name = 'OfflineImmediateCommandRejectedError';
|
|
2861
|
+
}
|
|
2862
|
+
}
|
|
2854
2863
|
/** Raised before persistence when retaining another command would exceed the configured durable Outbox capacity. */
|
|
2855
2864
|
class OfflineOutboxCapacityError extends Error {
|
|
2856
2865
|
constructor(reason, currentCommands, currentBytes) {
|
|
@@ -2923,6 +2932,7 @@ class OfflineSyncService {
|
|
|
2923
2932
|
#flushTransitions;
|
|
2924
2933
|
#generation;
|
|
2925
2934
|
#sendingTransitions;
|
|
2935
|
+
#commandSendTransitions;
|
|
2926
2936
|
#retryTimer;
|
|
2927
2937
|
/** When non-null, automatic flushes pull only foreground scopes plus Outbox scopes. */
|
|
2928
2938
|
#foregroundScopePolicy;
|
|
@@ -2957,6 +2967,7 @@ class OfflineSyncService {
|
|
|
2957
2967
|
this.#flushTransitions = new Set();
|
|
2958
2968
|
this.#generation = 0;
|
|
2959
2969
|
this.#sendingTransitions = new Set();
|
|
2970
|
+
this.#commandSendTransitions = new Map();
|
|
2960
2971
|
this.#retryTimer = null;
|
|
2961
2972
|
/** When non-null, automatic flushes pull only foreground scopes plus Outbox scopes. */
|
|
2962
2973
|
this.#foregroundScopePolicy = null;
|
|
@@ -3262,7 +3273,10 @@ class OfflineSyncService {
|
|
|
3262
3273
|
this.noteScope(scope);
|
|
3263
3274
|
const commandIdentity = offlineCommandLookupIdentity(request.identity);
|
|
3264
3275
|
const normalized = await this.#normalizeEnqueueRequest(scope, request, commandIdentity, repository);
|
|
3265
|
-
const commandId = crypto.randomUUID();
|
|
3276
|
+
const commandId = request.commandId ?? crypto.randomUUID();
|
|
3277
|
+
if (typeof commandId !== 'string' || commandId.length === 0 || commandId.length > 255) {
|
|
3278
|
+
throw new Error('Offline command id must contain between 1 and 255 characters.');
|
|
3279
|
+
}
|
|
3266
3280
|
const sourceKey = this.#hooks.entityType(request);
|
|
3267
3281
|
const localOnlyFootprint = this.#normalizedLocalOnlyFootprint(scope, request.localOnlyFootprint);
|
|
3268
3282
|
if (replaced)
|
|
@@ -3378,6 +3392,7 @@ class OfflineSyncService {
|
|
|
3378
3392
|
#assertDistinctBatchFootprints(entries, existingCommands, allowOneAggregate = false) {
|
|
3379
3393
|
const aggregates = new Set();
|
|
3380
3394
|
const replicaKeys = new Set();
|
|
3395
|
+
const commandIds = new Set(existingCommands.map((command) => command.commandId));
|
|
3381
3396
|
const existingFootprints = new Map();
|
|
3382
3397
|
for (const command of existingCommands) {
|
|
3383
3398
|
const aggregate = this.#aggregateKey(command);
|
|
@@ -3385,6 +3400,10 @@ class OfflineSyncService {
|
|
|
3385
3400
|
existingFootprints.set(key, aggregate);
|
|
3386
3401
|
}
|
|
3387
3402
|
for (const entry of entries) {
|
|
3403
|
+
if (commandIds.has(entry.command.commandId)) {
|
|
3404
|
+
throw new Error(`Offline command id ${entry.command.commandId} is already in use.`);
|
|
3405
|
+
}
|
|
3406
|
+
commandIds.add(entry.command.commandId);
|
|
3388
3407
|
const aggregate = this.#aggregateKey(entry.command);
|
|
3389
3408
|
if (aggregates.has(aggregate) && !allowOneAggregate) {
|
|
3390
3409
|
throw new Error('Prepared offline batch contains overlapping aggregate intents.');
|
|
@@ -3582,11 +3601,137 @@ class OfflineSyncService {
|
|
|
3582
3601
|
const generation = this.#generation;
|
|
3583
3602
|
return this.#flushAfterInitialization(generation);
|
|
3584
3603
|
}
|
|
3604
|
+
/**
|
|
3605
|
+
* Sends one newly-created generated aggregate immediately after its durable
|
|
3606
|
+
* enqueue, without waiting for a pre-send pull.
|
|
3607
|
+
*
|
|
3608
|
+
* This fast path is deliberately narrow: the command must still be pending,
|
|
3609
|
+
* have no remote id or confirmed baseline, and be the first intent for its
|
|
3610
|
+
* aggregate. Existing aggregates continue through {@link flush}, where the
|
|
3611
|
+
* pre-pull conflict barrier remains mandatory. Authoritative pull
|
|
3612
|
+
* reconciliation is scheduled in the background after the local transport
|
|
3613
|
+
* acknowledgement has been committed.
|
|
3614
|
+
*
|
|
3615
|
+
* @returns The generated remote id when transport completed locally, or
|
|
3616
|
+
* `null` when transport is unavailable or did not produce a confirmed id.
|
|
3617
|
+
*/
|
|
3618
|
+
async sendGeneratedCommandNow(commandId, locator) {
|
|
3619
|
+
const generation = this.#generation;
|
|
3620
|
+
if (!(await this.#restoreCurrentGeneration(generation)))
|
|
3621
|
+
return null;
|
|
3622
|
+
const userId = this.#activeUserId;
|
|
3623
|
+
if (userId === null)
|
|
3624
|
+
return null;
|
|
3625
|
+
return this.#beginGeneratedCommandSend(commandId, locator, generation, userId);
|
|
3626
|
+
}
|
|
3585
3627
|
async #flushAfterInitialization(generation) {
|
|
3586
3628
|
if (!(await this.#restoreCurrentGeneration(generation)))
|
|
3587
3629
|
return;
|
|
3588
3630
|
return this.#beginFlush(true);
|
|
3589
3631
|
}
|
|
3632
|
+
#beginGeneratedCommandSend(commandId, locator, generation, userId) {
|
|
3633
|
+
const result = this.#runGeneratedCommandSend(commandId, locator, generation, userId);
|
|
3634
|
+
let requiresReconciliation = false;
|
|
3635
|
+
const transition = result
|
|
3636
|
+
.then((remoteId) => {
|
|
3637
|
+
requiresReconciliation = remoteId !== null;
|
|
3638
|
+
}, () => undefined)
|
|
3639
|
+
.finally(() => {
|
|
3640
|
+
this.#flushTransitions.delete(transition);
|
|
3641
|
+
if (requiresReconciliation && this.#canSynchronize() && this.#isCurrentUser(generation, userId)) {
|
|
3642
|
+
// A normal flush may already be in its post-pull phase. Ensure the
|
|
3643
|
+
// newly acknowledged command receives a later reconciliation pass.
|
|
3644
|
+
if (this.#flushPromise)
|
|
3645
|
+
this.#resumeAfterFlush = true;
|
|
3646
|
+
queueMicrotask(() => this.#flushInBackground());
|
|
3647
|
+
}
|
|
3648
|
+
});
|
|
3649
|
+
this.#flushTransitions.add(transition);
|
|
3650
|
+
return result;
|
|
3651
|
+
}
|
|
3652
|
+
async #runGeneratedCommandSend(commandId, locator, generation, userId) {
|
|
3653
|
+
if (!this.#isCurrentUser(generation, userId))
|
|
3654
|
+
return null;
|
|
3655
|
+
if (!this.#canSynchronize()) {
|
|
3656
|
+
await this.#refreshState(generation);
|
|
3657
|
+
return null;
|
|
3658
|
+
}
|
|
3659
|
+
if (this.#pullAttentions().length > 0)
|
|
3660
|
+
return null;
|
|
3661
|
+
if (!(await this.#discoverScopes(generation)))
|
|
3662
|
+
return null;
|
|
3663
|
+
if (!this.#isCurrentUser(generation, userId))
|
|
3664
|
+
return null;
|
|
3665
|
+
const known = await this.#readKnownCommands();
|
|
3666
|
+
if (!this.#isCurrentUser(generation, userId))
|
|
3667
|
+
return null;
|
|
3668
|
+
const command = known.find((candidate) => candidate.commandId === commandId);
|
|
3669
|
+
if (!command)
|
|
3670
|
+
return this.#generatedRemoteId(locator, userId, generation);
|
|
3671
|
+
if (command.userId !== userId)
|
|
3672
|
+
return null;
|
|
3673
|
+
if (command.scopeId !== locator.scopeId ||
|
|
3674
|
+
command.sourceKey !== locator.sourceKey ||
|
|
3675
|
+
command.identity.kind !== 'generated' ||
|
|
3676
|
+
command.identity.localId !== locator.localId) {
|
|
3677
|
+
throw new Error('Immediate generated command locator does not match the durable command.');
|
|
3678
|
+
}
|
|
3679
|
+
if (command.state === 'awaiting_pull') {
|
|
3680
|
+
return this.#commandReconciliationRemoteId(command) ?? this.#generatedRemoteId(locator, userId, generation);
|
|
3681
|
+
}
|
|
3682
|
+
if (command.state !== 'pending')
|
|
3683
|
+
return null;
|
|
3684
|
+
const aggregate = known.filter((candidate) => this.#aggregateKey(candidate) === this.#aggregateKey(command));
|
|
3685
|
+
if (aggregate[0]?.commandId !== command.commandId) {
|
|
3686
|
+
throw new Error('Immediate generated command delivery requires the first aggregate intent.');
|
|
3687
|
+
}
|
|
3688
|
+
const row = await this.#rowForCommand(command);
|
|
3689
|
+
if (!row ||
|
|
3690
|
+
row.identity.kind !== 'generated' ||
|
|
3691
|
+
row.identity.remoteId !== null ||
|
|
3692
|
+
row.confirmedValues !== null ||
|
|
3693
|
+
command.identity.kind !== 'generated' ||
|
|
3694
|
+
command.baseRevision !== null ||
|
|
3695
|
+
command.replicaMutation === 'delete') {
|
|
3696
|
+
throw new Error('Immediate generated command delivery requires a new unconfirmed aggregate.');
|
|
3697
|
+
}
|
|
3698
|
+
const scope = { userId: command.userId, scopeId: command.scopeId };
|
|
3699
|
+
const scopeKey = this.#scopeKey(scope);
|
|
3700
|
+
if (!this.#knownScopes.has(scopeKey))
|
|
3701
|
+
return null;
|
|
3702
|
+
const dirtyScopes = new Map();
|
|
3703
|
+
await this.#sendAggregate([command], generation, dirtyScopes, new Set([scopeKey]));
|
|
3704
|
+
if (!this.#isCurrentUser(generation, userId))
|
|
3705
|
+
return null;
|
|
3706
|
+
for (const dirtyScope of dirtyScopes.values()) {
|
|
3707
|
+
this.#pendingPullScopes.set(this.#scopeKey(dirtyScope), dirtyScope);
|
|
3708
|
+
}
|
|
3709
|
+
await this.#refreshState(generation);
|
|
3710
|
+
if (!this.#isCurrentUser(generation, userId))
|
|
3711
|
+
return null;
|
|
3712
|
+
const completed = (await this.#readKnownCommands()).find((candidate) => candidate.commandId === commandId);
|
|
3713
|
+
if (!this.#isCurrentUser(generation, userId))
|
|
3714
|
+
return null;
|
|
3715
|
+
if (completed && ['blocked_auth', 'rejected', 'conflict'].includes(completed.state)) {
|
|
3716
|
+
throw new OfflineImmediateCommandRejectedError(completed.state, completed.lastErrorCode);
|
|
3717
|
+
}
|
|
3718
|
+
return completed
|
|
3719
|
+
? (this.#commandReconciliationRemoteId(completed) ?? this.#generatedRemoteId(locator, userId, generation))
|
|
3720
|
+
: this.#generatedRemoteId(locator, userId, generation);
|
|
3721
|
+
}
|
|
3722
|
+
async #generatedRemoteId(locator, userId, generation) {
|
|
3723
|
+
if (!this.#isCurrentUser(generation, userId))
|
|
3724
|
+
return null;
|
|
3725
|
+
const row = await this.#repository.getReplicaRow({ userId, scopeId: locator.scopeId }, locator.sourceKey, {
|
|
3726
|
+
kind: 'generated',
|
|
3727
|
+
localId: locator.localId,
|
|
3728
|
+
});
|
|
3729
|
+
return this.#isCurrentUser(generation, userId) && row?.identity.kind === 'generated' ? row.identity.remoteId : null;
|
|
3730
|
+
}
|
|
3731
|
+
#commandReconciliationRemoteId(command) {
|
|
3732
|
+
const identity = command.reconciliationIdentity;
|
|
3733
|
+
return identity && 'remoteId' in identity ? (identity.remoteId ?? null) : null;
|
|
3734
|
+
}
|
|
3590
3735
|
#beginFlush(explicitFull) {
|
|
3591
3736
|
const lifecycleRevision = this.#lifecycleRevision();
|
|
3592
3737
|
const isPartial = !explicitFull && this.#foregroundScopePolicy !== null;
|
|
@@ -3856,75 +4001,94 @@ class OfflineSyncService {
|
|
|
3856
4001
|
}
|
|
3857
4002
|
async #sendAggregate(commands, generation, dirtyScopes, pulledScopeKeys) {
|
|
3858
4003
|
for (const command of commands) {
|
|
3859
|
-
if (!this.#
|
|
3860
|
-
return;
|
|
3861
|
-
if (command.state === 'awaiting_pull')
|
|
3862
|
-
continue;
|
|
3863
|
-
if (command.state === 'retry_wait' && (command.retryAt ?? 0) > Date.now())
|
|
3864
|
-
break;
|
|
3865
|
-
if (!['pending', 'retry_wait'].includes(command.state))
|
|
3866
|
-
break;
|
|
3867
|
-
// User-scoped aggregates ignore scopeId in the FIFO key, so later commands may
|
|
3868
|
-
// belong to scopes that failed pre-pull even when the head was admitted.
|
|
3869
|
-
if (!pulledScopeKeys.has(this.#scopeKey({ userId: command.userId, scopeId: command.scopeId })))
|
|
4004
|
+
if (!(await this.#sendCommandOnce(commands, command, generation, dirtyScopes, pulledScopeKeys)))
|
|
3870
4005
|
break;
|
|
3871
|
-
|
|
3872
|
-
|
|
3873
|
-
|
|
4006
|
+
}
|
|
4007
|
+
}
|
|
4008
|
+
#sendCommandOnce(aggregateCommands, command, generation, dirtyScopes, pulledScopeKeys) {
|
|
4009
|
+
const transitionKey = this.#commandSendKey(command, generation);
|
|
4010
|
+
const active = this.#commandSendTransitions.get(transitionKey);
|
|
4011
|
+
if (active)
|
|
4012
|
+
return active;
|
|
4013
|
+
const transition = this.#sendCommand(aggregateCommands, command, generation, dirtyScopes, pulledScopeKeys).finally(() => {
|
|
4014
|
+
if (this.#commandSendTransitions.get(transitionKey) === transition) {
|
|
4015
|
+
this.#commandSendTransitions.delete(transitionKey);
|
|
4016
|
+
}
|
|
4017
|
+
});
|
|
4018
|
+
this.#commandSendTransitions.set(transitionKey, transition);
|
|
4019
|
+
return transition;
|
|
4020
|
+
}
|
|
4021
|
+
#commandSendKey(command, generation) {
|
|
4022
|
+
return JSON.stringify([generation, canonicalOfflinePrincipalId(command.userId), command.commandId]);
|
|
4023
|
+
}
|
|
4024
|
+
async #sendCommand(aggregateCommands, command, generation, dirtyScopes, pulledScopeKeys) {
|
|
4025
|
+
if (!this.#isCurrent(generation))
|
|
4026
|
+
return false;
|
|
4027
|
+
if (command.state === 'awaiting_pull')
|
|
4028
|
+
return true;
|
|
4029
|
+
if (command.state === 'retry_wait' && (command.retryAt ?? 0) > Date.now())
|
|
4030
|
+
return false;
|
|
4031
|
+
if (!['pending', 'retry_wait'].includes(command.state))
|
|
4032
|
+
return false;
|
|
4033
|
+
// User-scoped aggregates ignore scopeId in the FIFO key, so later commands may
|
|
4034
|
+
// belong to scopes that failed pre-pull even when the head was admitted.
|
|
4035
|
+
if (!pulledScopeKeys.has(this.#scopeKey({ userId: command.userId, scopeId: command.scopeId })))
|
|
4036
|
+
return false;
|
|
4037
|
+
let sending = await this.#claimSendingCommand(command, generation);
|
|
4038
|
+
if (!sending || !this.#isCurrent(generation))
|
|
4039
|
+
return false;
|
|
4040
|
+
await this.#refreshState(generation);
|
|
4041
|
+
if (!this.#isCurrent(generation))
|
|
4042
|
+
return false;
|
|
4043
|
+
const claimedCommand = sending;
|
|
4044
|
+
const readRow = async () => this.#rowForCommand(claimedCommand);
|
|
4045
|
+
const rowResult = await readRow().then((row) => ({ status: 'fulfilled', row }), (error) => ({ status: 'rejected', error }));
|
|
4046
|
+
if (rowResult.status === 'rejected') {
|
|
3874
4047
|
if (!this.#isCurrent(generation))
|
|
3875
|
-
return;
|
|
3876
|
-
await this.#
|
|
4048
|
+
return false;
|
|
4049
|
+
await this.#persistFailedCommand(sending, rowResult.error, generation, null, sending.serverCommitUnknown === true);
|
|
4050
|
+
throw rowResult.error;
|
|
4051
|
+
}
|
|
4052
|
+
const row = rowResult.row;
|
|
4053
|
+
if (!row) {
|
|
4054
|
+
const error = new Error(`Offline replica row not found: ${sending.aggregateType}/${canonicalOfflineCommandIdentity(sending.identity)}`);
|
|
4055
|
+
await this.#persistFailedCommand(sending, error, generation, null, sending.serverCommitUnknown === true);
|
|
4056
|
+
throw error;
|
|
4057
|
+
}
|
|
4058
|
+
const priorCommitUnknown = sending.serverCommitUnknown === true;
|
|
4059
|
+
const transportCommand = await this.#markTransportStarted(sending, generation);
|
|
4060
|
+
if (!transportCommand)
|
|
4061
|
+
return false;
|
|
4062
|
+
sending = transportCommand;
|
|
4063
|
+
const executeCommand = async () => this.#executor.execute(sending, offlineCommandTargetFromReplicaRow(row));
|
|
4064
|
+
const execution = await executeCommand().then((result) => ({ status: 'fulfilled', result }), (error) => ({ status: 'rejected', error }));
|
|
4065
|
+
if (execution.status === 'rejected') {
|
|
3877
4066
|
if (!this.#isCurrent(generation))
|
|
3878
|
-
return;
|
|
3879
|
-
const
|
|
3880
|
-
|
|
3881
|
-
|
|
3882
|
-
|
|
3883
|
-
|
|
3884
|
-
|
|
3885
|
-
|
|
3886
|
-
|
|
3887
|
-
|
|
3888
|
-
|
|
3889
|
-
|
|
3890
|
-
|
|
3891
|
-
|
|
3892
|
-
|
|
3893
|
-
}
|
|
3894
|
-
const priorCommitUnknown = sending.serverCommitUnknown === true;
|
|
3895
|
-
const transportCommand = await this.#markTransportStarted(sending, generation);
|
|
3896
|
-
if (!transportCommand)
|
|
3897
|
-
return;
|
|
3898
|
-
sending = transportCommand;
|
|
3899
|
-
const executeCommand = async () => this.#executor.execute(sending, offlineCommandTargetFromReplicaRow(row));
|
|
3900
|
-
const execution = await executeCommand().then((result) => ({ status: 'fulfilled', result }), (error) => ({ status: 'rejected', error }));
|
|
3901
|
-
if (execution.status === 'rejected') {
|
|
3902
|
-
if (!this.#isCurrent(generation))
|
|
3903
|
-
return;
|
|
3904
|
-
const commitUnknown = this.#executor.provesCommandNotCommitted?.(execution.error, sending)
|
|
3905
|
-
? false
|
|
3906
|
-
: priorCommitUnknown || this.#serverCommitCouldBeUnknown(execution.error);
|
|
3907
|
-
await this.#persistFailedCommand(sending, execution.error, generation, row, commitUnknown);
|
|
3908
|
-
if (!this.#isClassifiableTransportError(execution.error))
|
|
3909
|
-
throw execution.error;
|
|
3910
|
-
break;
|
|
3911
|
-
}
|
|
3912
|
-
const result = execution.result;
|
|
4067
|
+
return false;
|
|
4068
|
+
const commitUnknown = this.#executor.provesCommandNotCommitted?.(execution.error, sending)
|
|
4069
|
+
? false
|
|
4070
|
+
: priorCommitUnknown || this.#serverCommitCouldBeUnknown(execution.error);
|
|
4071
|
+
await this.#persistFailedCommand(sending, execution.error, generation, row, commitUnknown);
|
|
4072
|
+
if (!this.#isClassifiableTransportError(execution.error))
|
|
4073
|
+
throw execution.error;
|
|
4074
|
+
return false;
|
|
4075
|
+
}
|
|
4076
|
+
const result = execution.result;
|
|
4077
|
+
if (!this.#isCurrent(generation))
|
|
4078
|
+
return false;
|
|
4079
|
+
const completeCommand = async () => this.#completeCommandWithRetry(aggregateCommands, sending, result, generation);
|
|
4080
|
+
const completion = await completeCommand().then(() => ({ status: 'fulfilled' }), (error) => ({ status: 'rejected', error }));
|
|
4081
|
+
if (completion.status === 'rejected') {
|
|
3913
4082
|
if (!this.#isCurrent(generation))
|
|
3914
|
-
return;
|
|
3915
|
-
|
|
3916
|
-
|
|
3917
|
-
if (completion.status === 'rejected') {
|
|
3918
|
-
if (!this.#isCurrent(generation))
|
|
3919
|
-
return;
|
|
3920
|
-
await this.#persistFailedCommand(sending, completion.error, generation, row, true);
|
|
3921
|
-
throw completion.error;
|
|
3922
|
-
}
|
|
3923
|
-
if (this.#isCurrent(generation)) {
|
|
3924
|
-
const scope = { userId: sending.userId, scopeId: sending.scopeId };
|
|
3925
|
-
dirtyScopes.set(this.#scopeKey(scope), scope);
|
|
3926
|
-
}
|
|
4083
|
+
return false;
|
|
4084
|
+
await this.#persistFailedCommand(sending, completion.error, generation, row, true);
|
|
4085
|
+
throw completion.error;
|
|
3927
4086
|
}
|
|
4087
|
+
if (this.#isCurrent(generation)) {
|
|
4088
|
+
const scope = { userId: sending.userId, scopeId: sending.scopeId };
|
|
4089
|
+
dirtyScopes.set(this.#scopeKey(scope), scope);
|
|
4090
|
+
}
|
|
4091
|
+
return true;
|
|
3928
4092
|
}
|
|
3929
4093
|
async #normalizeEnqueueRequest(scope, request, commandIdentity, repository) {
|
|
3930
4094
|
let baseRevision = request.baseRevision ?? null;
|
|
@@ -4354,6 +4518,9 @@ class OfflineSyncService {
|
|
|
4354
4518
|
#isCurrent(generation) {
|
|
4355
4519
|
return generation === this.#generation;
|
|
4356
4520
|
}
|
|
4521
|
+
#isCurrentUser(generation, userId) {
|
|
4522
|
+
return this.#isCurrent(generation) && this.#activeUserId === userId;
|
|
4523
|
+
}
|
|
4357
4524
|
async #restoreInterruptedCommands() {
|
|
4358
4525
|
const commands = await this.#readKnownCommands();
|
|
4359
4526
|
await Promise.all(commands
|
|
@@ -4435,7 +4602,7 @@ class OfflineSyncService {
|
|
|
4435
4602
|
this.#pendingPullScopes.delete(this.#scopeKey(scope));
|
|
4436
4603
|
}
|
|
4437
4604
|
async #waitForSendingTransitions() {
|
|
4438
|
-
await Promise.allSettled([...this.#sendingTransitions]);
|
|
4605
|
+
await Promise.allSettled([...this.#sendingTransitions, ...this.#commandSendTransitions.values()]);
|
|
4439
4606
|
}
|
|
4440
4607
|
#canonicalJson(value) {
|
|
4441
4608
|
if (Array.isArray(value))
|
|
@@ -4876,6 +5043,7 @@ class OfflineCoordinatorService {
|
|
|
4876
5043
|
...(ngDevMode ? [{ debugName: "isStorageReady" }] : /* istanbul ignore next */ []));
|
|
4877
5044
|
this.networkState = this.#network.state;
|
|
4878
5045
|
this.syncState = this.#sync.syncState;
|
|
5046
|
+
this.pendingCommands = this.#sync.pendingCommands;
|
|
4879
5047
|
this.pendingCount = this.#sync.pendingCount;
|
|
4880
5048
|
this.conflicts = this.#sync.conflicts;
|
|
4881
5049
|
/** Device-local control for accepting new durable Outbox mutations. */
|
|
@@ -5441,6 +5609,9 @@ const offlineInterceptor = (request, next) => {
|
|
|
5441
5609
|
const plan = registry.resolve(request);
|
|
5442
5610
|
if (!plan)
|
|
5443
5611
|
return transport();
|
|
5612
|
+
if (plan.readStrategy === 'local-only') {
|
|
5613
|
+
return readLocalOnly(plan, inject(ErrorHandler), inject(OfflineReplicaMutationCoordinator));
|
|
5614
|
+
}
|
|
5444
5615
|
if (plan.readStrategy === 'local-first') {
|
|
5445
5616
|
return readLocalFirst(request, plan, transport, fallback, inject(ErrorHandler), inject(OfflineReplicaMutationCoordinator));
|
|
5446
5617
|
}
|
|
@@ -5459,6 +5630,10 @@ const offlineInterceptor = (request, next) => {
|
|
|
5459
5630
|
}
|
|
5460
5631
|
return transport();
|
|
5461
5632
|
};
|
|
5633
|
+
/** Resolves a provisional/local identity without starting remote transport. */
|
|
5634
|
+
function readLocalOnly(plan, errorHandler, replicaMutations) {
|
|
5635
|
+
return resolveLocalAttempt(plan, errorHandler, replicaMutations).pipe(concatMap((response) => (response ? of(response) : EMPTY)));
|
|
5636
|
+
}
|
|
5462
5637
|
function readNetworkFirst(request, plan, transport, fallback, replicaMutations) {
|
|
5463
5638
|
return defer(transport).pipe(catchError((error) => fallback.handle(request, error, plan) ?? throwError(() => error)), concatMap((event) => projectReadResponse(event, plan, replicaMutations)));
|
|
5464
5639
|
}
|
|
@@ -7030,5 +7205,5 @@ function assertSupportedOfflineMode(platform, mode) {
|
|
|
7030
7205
|
* Generated bundle index. Do not edit.
|
|
7031
7206
|
*/
|
|
7032
7207
|
|
|
7033
|
-
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 };
|
|
7208
|
+
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, OfflineImmediateCommandRejectedError, 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 };
|
|
7034
7209
|
//# sourceMappingURL=rdlabo-ionic-angular-kit-offline.mjs.map
|