@rdlabo/ionic-angular-kit 22.0.0-beta.pr96.shaa32019794c9b → 22.0.0-beta.pr97.sha8de46c91cfe0
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.
|
@@ -933,6 +933,33 @@ function offlineCommandLookupIdentity(identity) {
|
|
|
933
933
|
* This symbol is intentionally not re-exported from the package entry point.
|
|
934
934
|
*/
|
|
935
935
|
const OFFLINE_REPOSITORY_ATOMIC_MUTATION = Symbol('OFFLINE_REPOSITORY_ATOMIC_MUTATION');
|
|
936
|
+
/** Internal typed boundary for a local write that is safe to recompute once from a fresh snapshot. */
|
|
937
|
+
class OfflineReplicaTransientWriteError extends Error {
|
|
938
|
+
constructor(reason, message, options) {
|
|
939
|
+
super(message, options);
|
|
940
|
+
this.reason = reason;
|
|
941
|
+
this.name = 'OfflineReplicaTransientWriteError';
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
function normalizeOfflineReplicaTransientWriteError(error) {
|
|
945
|
+
if (error instanceof OfflineReplicaTransientWriteError)
|
|
946
|
+
return error;
|
|
947
|
+
const code = typeof error === 'object' && error !== null && typeof error.code === 'string'
|
|
948
|
+
? error.code.toUpperCase()
|
|
949
|
+
: '';
|
|
950
|
+
const message = error instanceof Error ? error.message : typeof error === 'string' ? error : '';
|
|
951
|
+
const normalizedMessage = message.toUpperCase();
|
|
952
|
+
if (code.includes('SQLITE_BUSY') || normalizedMessage.includes('SQLITE_BUSY')) {
|
|
953
|
+
return new OfflineReplicaTransientWriteError('sqlite_busy', message || 'SQLite is busy.', { cause: error });
|
|
954
|
+
}
|
|
955
|
+
if (code.includes('SQLITE_LOCKED') ||
|
|
956
|
+
normalizedMessage.includes('SQLITE_LOCKED') ||
|
|
957
|
+
message.includes('database is locked') ||
|
|
958
|
+
message.includes('database table is locked')) {
|
|
959
|
+
return new OfflineReplicaTransientWriteError('sqlite_locked', message || 'SQLite database is locked.', { cause: error });
|
|
960
|
+
}
|
|
961
|
+
return error;
|
|
962
|
+
}
|
|
936
963
|
|
|
937
964
|
/** Current durable storage schema used by both web and native repositories. */
|
|
938
965
|
const OFFLINE_SCHEMA_VERSION = 2;
|
|
@@ -3138,7 +3165,7 @@ class OfflineSyncService {
|
|
|
3138
3165
|
const materializations = [];
|
|
3139
3166
|
for (const [index, entry] of prepared.entries()) {
|
|
3140
3167
|
this.#assertEnqueueScope(session, entry.request.scopeId);
|
|
3141
|
-
materializations.push(await this.#materializeEnqueue(session.userId, entry.request, replaced[index]));
|
|
3168
|
+
materializations.push(await this.#materializeEnqueue(session.userId, entry.request, repository, replaced[index]));
|
|
3142
3169
|
}
|
|
3143
3170
|
const retained = knownCommands.filter((command) => !replaced.some((item) => item.commandId === command.commandId));
|
|
3144
3171
|
this.#assertDistinctBatchFootprints(materializations, retained, true);
|
|
@@ -3181,8 +3208,8 @@ class OfflineSyncService {
|
|
|
3181
3208
|
async #enqueue(request, options, generation, replaced, repository = this.#repository) {
|
|
3182
3209
|
const session = await this.#beginEnqueueSession(generation);
|
|
3183
3210
|
this.#assertEnqueueScope(session, request.scopeId);
|
|
3184
|
-
const materialization = await this.#materializeEnqueue(session.userId, request, replaced);
|
|
3185
|
-
const currentCommands = await this.#commandsForUser(session.userId);
|
|
3211
|
+
const materialization = await this.#materializeEnqueue(session.userId, request, repository, replaced);
|
|
3212
|
+
const currentCommands = await this.#commandsForUser(session.userId, repository);
|
|
3186
3213
|
const retainedCommands = replaced ? currentCommands.filter((command) => command.commandId !== replaced.commandId) : currentCommands;
|
|
3187
3214
|
this.#assertDistinctBatchFootprints([materialization], retainedCommands);
|
|
3188
3215
|
await this.#assertOutboxCapacity(session.userId, [materialization.command], replaced ? [replaced.commandId] : undefined, currentCommands);
|
|
@@ -3194,14 +3221,14 @@ class OfflineSyncService {
|
|
|
3194
3221
|
throw new Error('Prepared offline batch must contain at least one command.');
|
|
3195
3222
|
}
|
|
3196
3223
|
const session = await this.#beginEnqueueSession(generation);
|
|
3197
|
-
const currentCommands = await this.#commandsForUser(session.userId);
|
|
3224
|
+
const currentCommands = await this.#commandsForUser(session.userId, repository);
|
|
3198
3225
|
this.#rememberCreatedAt(currentCommands);
|
|
3199
3226
|
const firstCreatedAt = Math.max(Date.now(), this.#lastCommandCreatedAt + 1);
|
|
3200
3227
|
this.#lastCommandCreatedAt = firstCreatedAt + prepared.length - 1;
|
|
3201
3228
|
const materializations = [];
|
|
3202
3229
|
for (const [index, entry] of prepared.entries()) {
|
|
3203
3230
|
this.#assertEnqueueScope(session, entry.request.scopeId);
|
|
3204
|
-
materializations.push(await this.#materializeEnqueue(session.userId, entry.request, undefined, firstCreatedAt + index));
|
|
3231
|
+
materializations.push(await this.#materializeEnqueue(session.userId, entry.request, repository, undefined, firstCreatedAt + index));
|
|
3205
3232
|
}
|
|
3206
3233
|
this.#assertDistinctBatchFootprints(materializations, currentCommands);
|
|
3207
3234
|
await this.#assertOutboxCapacity(session.userId, materializations.map((item) => item.command), undefined, currentCommands);
|
|
@@ -3230,11 +3257,11 @@ class OfflineSyncService {
|
|
|
3230
3257
|
}
|
|
3231
3258
|
this.noteScope({ userId: session.userId, scopeId });
|
|
3232
3259
|
}
|
|
3233
|
-
async #materializeEnqueue(userId, request, replaced, createdAt) {
|
|
3260
|
+
async #materializeEnqueue(userId, request, repository, replaced, createdAt) {
|
|
3234
3261
|
const scope = { userId, scopeId: request.scopeId };
|
|
3235
3262
|
this.noteScope(scope);
|
|
3236
3263
|
const commandIdentity = offlineCommandLookupIdentity(request.identity);
|
|
3237
|
-
const normalized = await this.#normalizeEnqueueRequest(scope, request, commandIdentity);
|
|
3264
|
+
const normalized = await this.#normalizeEnqueueRequest(scope, request, commandIdentity, repository);
|
|
3238
3265
|
const commandId = crypto.randomUUID();
|
|
3239
3266
|
const sourceKey = this.#hooks.entityType(request);
|
|
3240
3267
|
const localOnlyFootprint = this.#normalizedLocalOnlyFootprint(scope, request.localOnlyFootprint);
|
|
@@ -3253,7 +3280,7 @@ class OfflineSyncService {
|
|
|
3253
3280
|
state: 'pending',
|
|
3254
3281
|
attempts: 0,
|
|
3255
3282
|
retryAt: null,
|
|
3256
|
-
createdAt: replaced?.createdAt ?? createdAt ?? (await this.#nextCommandCreatedAt(userId)),
|
|
3283
|
+
createdAt: replaced?.createdAt ?? createdAt ?? (await this.#nextCommandCreatedAt(userId, repository)),
|
|
3257
3284
|
lastErrorCode: null,
|
|
3258
3285
|
};
|
|
3259
3286
|
if (localOnlyFootprint.length > 0)
|
|
@@ -3277,10 +3304,10 @@ class OfflineSyncService {
|
|
|
3277
3304
|
if (schema.identity.kind === 'naturalKey' && request.identity.kind !== 'natural') {
|
|
3278
3305
|
throw new Error(`Offline replica source "${entityType}" requires natural identity.`);
|
|
3279
3306
|
}
|
|
3280
|
-
if (request.replicaMutation === 'delete' && !
|
|
3307
|
+
if (request.replicaMutation === 'delete' && !repository.getReplicaRowIncludingPendingDelete) {
|
|
3281
3308
|
throw new Error('Offline repository does not support durable replica delete tombstones.');
|
|
3282
3309
|
}
|
|
3283
|
-
const existing = await this.#getReplicaRowForSync(scope, entityType, commandIdentity);
|
|
3310
|
+
const existing = await this.#getReplicaRowForSync(scope, entityType, commandIdentity, repository);
|
|
3284
3311
|
const generatedIdentity = request.identity.kind === 'generated' ? request.identity : null;
|
|
3285
3312
|
const initialRemoteId = this.#initialRemoteId(schema, existing?.identity.kind === 'generated' ? existing.identity.remoteId : null, generatedIdentity?.remoteId);
|
|
3286
3313
|
this.#assertRemoteIdHint(schema, existing?.identity.kind === 'generated' ? existing.identity.remoteId : null, generatedIdentity?.remoteIdHint);
|
|
@@ -3312,7 +3339,7 @@ class OfflineSyncService {
|
|
|
3312
3339
|
}
|
|
3313
3340
|
}
|
|
3314
3341
|
if (remoteIdentity !== null) {
|
|
3315
|
-
const mapped = await
|
|
3342
|
+
const mapped = await repository.getReplicaRowByRemoteIdentity(scope, entityType, remoteIdentity);
|
|
3316
3343
|
if (mapped !== null && !commandIdentityMatchesReplicaRow(schema, mapped, commandIdentity)) {
|
|
3317
3344
|
if ('remoteId' in remoteIdentity) {
|
|
3318
3345
|
throw new Error(`Offline replica remote id ${String(remoteIdentity.remoteId)} is already mapped to another row.`);
|
|
@@ -3404,7 +3431,7 @@ class OfflineSyncService {
|
|
|
3404
3431
|
putCommands: entries.map((entry) => entry.command),
|
|
3405
3432
|
removeCommandIds,
|
|
3406
3433
|
});
|
|
3407
|
-
await this.#refreshState().catch((error) => this.#reportError(error));
|
|
3434
|
+
await this.#refreshState(generation, repository).catch((error) => this.#reportError(error));
|
|
3408
3435
|
if (options.flush !== false && this.#canSynchronize())
|
|
3409
3436
|
this.#flushInBackground();
|
|
3410
3437
|
}
|
|
@@ -3885,7 +3912,7 @@ class OfflineSyncService {
|
|
|
3885
3912
|
const result = execution.result;
|
|
3886
3913
|
if (!this.#isCurrent(generation))
|
|
3887
3914
|
return;
|
|
3888
|
-
const completeCommand = async () => this.#
|
|
3915
|
+
const completeCommand = async () => this.#completeCommandWithRetry(commands, sending, result, generation);
|
|
3889
3916
|
const completion = await completeCommand().then(() => ({ status: 'fulfilled' }), (error) => ({ status: 'rejected', error }));
|
|
3890
3917
|
if (completion.status === 'rejected') {
|
|
3891
3918
|
if (!this.#isCurrent(generation))
|
|
@@ -3899,10 +3926,10 @@ class OfflineSyncService {
|
|
|
3899
3926
|
}
|
|
3900
3927
|
}
|
|
3901
3928
|
}
|
|
3902
|
-
async #normalizeEnqueueRequest(scope, request, commandIdentity) {
|
|
3929
|
+
async #normalizeEnqueueRequest(scope, request, commandIdentity, repository) {
|
|
3903
3930
|
let baseRevision = request.baseRevision ?? null;
|
|
3904
3931
|
const sourceKey = this.#hooks.entityType(request);
|
|
3905
|
-
const row = await this.#getReplicaRowForSync(scope, sourceKey, commandIdentity);
|
|
3932
|
+
const row = await this.#getReplicaRowForSync(scope, sourceKey, commandIdentity, repository);
|
|
3906
3933
|
if (row?.serverRevision != null && row.serverRevision !== baseRevision) {
|
|
3907
3934
|
baseRevision = row.serverRevision;
|
|
3908
3935
|
}
|
|
@@ -3911,6 +3938,18 @@ class OfflineSyncService {
|
|
|
3911
3938
|
async #completeCommand(commands, command, result, generation) {
|
|
3912
3939
|
return this.#serializeReplicaMutation((repository) => this.#completeCommandLocked(commands, command, result, generation, repository));
|
|
3913
3940
|
}
|
|
3941
|
+
async #completeCommandWithRetry(commands, command, result, generation) {
|
|
3942
|
+
return this.#completeCommand(commands, command, result, generation).catch(async (firstError) => {
|
|
3943
|
+
if (!isRetryableLocalCompletionError(firstError))
|
|
3944
|
+
throw firstError;
|
|
3945
|
+
const retry = await this.#completeCommand(commands, command, result, generation).then(() => ({ status: 'fulfilled' }), (error) => ({ status: 'rejected', error }));
|
|
3946
|
+
if (retry.status === 'fulfilled')
|
|
3947
|
+
return;
|
|
3948
|
+
if (!isRetryableLocalCompletionError(retry.error))
|
|
3949
|
+
throw retry.error;
|
|
3950
|
+
throw new OfflineLocalCompletionError(retry.error, firstError);
|
|
3951
|
+
});
|
|
3952
|
+
}
|
|
3914
3953
|
async #completeCommandLocked(commands, command, result, generation, repository) {
|
|
3915
3954
|
if (result.clearRemoteId === true && result.remoteId !== undefined) {
|
|
3916
3955
|
throw new Error('Offline command cannot return remoteId and clearRemoteId together.');
|
|
@@ -3918,7 +3957,7 @@ class OfflineSyncService {
|
|
|
3918
3957
|
if (result.clearRemoteId === true && result.serverRevision !== undefined) {
|
|
3919
3958
|
throw new Error('Offline command cannot return serverRevision and clearRemoteId together.');
|
|
3920
3959
|
}
|
|
3921
|
-
const latestCommands = (await this.#readKnownCommands()).filter((candidate) => this.#aggregateKey(candidate) === this.#aggregateKey(command));
|
|
3960
|
+
const latestCommands = (await this.#readKnownCommands(repository)).filter((candidate) => this.#aggregateKey(candidate) === this.#aggregateKey(command));
|
|
3922
3961
|
const latestIndex = latestCommands.findIndex((candidate) => candidate.commandId === command.commandId);
|
|
3923
3962
|
if (latestIndex < 0)
|
|
3924
3963
|
return;
|
|
@@ -3929,7 +3968,7 @@ class OfflineSyncService {
|
|
|
3929
3968
|
: revision === undefined
|
|
3930
3969
|
? following
|
|
3931
3970
|
: following.map((item) => offlineCommandWithBaseRevision(item, revision));
|
|
3932
|
-
const current = await this.#rowForCommand(command);
|
|
3971
|
+
const current = await this.#rowForCommand(command, repository);
|
|
3933
3972
|
if (!this.#isCurrent(generation))
|
|
3934
3973
|
return;
|
|
3935
3974
|
if (!current) {
|
|
@@ -4093,7 +4132,7 @@ class OfflineSyncService {
|
|
|
4093
4132
|
...command,
|
|
4094
4133
|
state: 'retry_wait',
|
|
4095
4134
|
retryAt,
|
|
4096
|
-
lastErrorCode: status > 0 ? String(status) : 'network',
|
|
4135
|
+
lastErrorCode: error instanceof OfflineLocalCompletionError ? 'local_completion' : status > 0 ? String(status) : 'network',
|
|
4097
4136
|
serverCommitUnknown,
|
|
4098
4137
|
};
|
|
4099
4138
|
}
|
|
@@ -4269,8 +4308,8 @@ class OfflineSyncService {
|
|
|
4269
4308
|
this.#rememberCreatedAt(commands);
|
|
4270
4309
|
return commands;
|
|
4271
4310
|
}
|
|
4272
|
-
async #nextCommandCreatedAt(userId) {
|
|
4273
|
-
const commands = await this.#commandsForUser(userId);
|
|
4311
|
+
async #nextCommandCreatedAt(userId, repository = this.#repository) {
|
|
4312
|
+
const commands = await this.#commandsForUser(userId, repository);
|
|
4274
4313
|
this.#rememberCreatedAt(commands);
|
|
4275
4314
|
const createdAt = Math.max(Date.now(), this.#lastCommandCreatedAt + 1);
|
|
4276
4315
|
this.#lastCommandCreatedAt = createdAt;
|
|
@@ -4432,6 +4471,17 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.3", ngImpor
|
|
|
4432
4471
|
function compareOfflineCommands(left, right) {
|
|
4433
4472
|
return left.createdAt - right.createdAt || (left.commandId < right.commandId ? -1 : left.commandId > right.commandId ? 1 : 0);
|
|
4434
4473
|
}
|
|
4474
|
+
class OfflineLocalCompletionError extends AggregateError {
|
|
4475
|
+
constructor(retryError, firstError) {
|
|
4476
|
+
super([firstError, retryError], 'Offline command reached the server but local acknowledgement could not be persisted.', {
|
|
4477
|
+
cause: retryError,
|
|
4478
|
+
});
|
|
4479
|
+
this.name = 'OfflineLocalCompletionError';
|
|
4480
|
+
}
|
|
4481
|
+
}
|
|
4482
|
+
function isRetryableLocalCompletionError(error) {
|
|
4483
|
+
return error instanceof OfflineReplicaTransientWriteError;
|
|
4484
|
+
}
|
|
4435
4485
|
|
|
4436
4486
|
/** Raised when disabling requires pending commands to be synchronized while transport is offline. */
|
|
4437
4487
|
class OfflineMutationPersistenceRequiresOnlineError extends Error {
|
|
@@ -5397,7 +5447,7 @@ const offlineInterceptor = (request, next) => {
|
|
|
5397
5447
|
if (plan.readStrategy === 'fastest-first') {
|
|
5398
5448
|
return readFastestFirst(request, plan, transport, fallback, inject(ErrorHandler), inject(OfflineReplicaMutationCoordinator));
|
|
5399
5449
|
}
|
|
5400
|
-
return readNetworkFirst(request, plan, transport, fallback);
|
|
5450
|
+
return readNetworkFirst(request, plan, transport, fallback, inject(OfflineReplicaMutationCoordinator));
|
|
5401
5451
|
}
|
|
5402
5452
|
if (LOCAL_FIRST_MUTATION_METHODS.has(request.method)) {
|
|
5403
5453
|
if (!inject(OFFLINE_MUTATION_PERSISTENCE_ENABLED)())
|
|
@@ -5409,8 +5459,8 @@ const offlineInterceptor = (request, next) => {
|
|
|
5409
5459
|
}
|
|
5410
5460
|
return transport();
|
|
5411
5461
|
};
|
|
5412
|
-
function readNetworkFirst(request, plan, transport, fallback) {
|
|
5413
|
-
return defer(transport).pipe(catchError((error) => fallback.handle(request, error, plan) ?? throwError(() => error)), concatMap((event) => projectReadResponse(event, plan)));
|
|
5462
|
+
function readNetworkFirst(request, plan, transport, fallback, replicaMutations) {
|
|
5463
|
+
return defer(transport).pipe(catchError((error) => fallback.handle(request, error, plan) ?? throwError(() => error)), concatMap((event) => projectReadResponse(event, plan, replicaMutations)));
|
|
5414
5464
|
}
|
|
5415
5465
|
/**
|
|
5416
5466
|
* Stale-while-revalidate local-first GET handling.
|
|
@@ -5427,18 +5477,18 @@ function readNetworkFirst(request, plan, transport, fallback) {
|
|
|
5427
5477
|
*/
|
|
5428
5478
|
function readLocalFirst(request, plan, transport, fallback, errorHandler, replicaMutations) {
|
|
5429
5479
|
return defer(transport).pipe(materialize(), connect((bufferedTransport$) => resolveLocalAttempt(plan, errorHandler, replicaMutations).pipe(concatMap((localResponse) => localResponse
|
|
5430
|
-
? concat(of(localResponse), drainRemoteAfterLocal(bufferedTransport$, plan))
|
|
5431
|
-
: drainRemoteNetworkFirst(bufferedTransport$, request, plan, fallback))), { connector: () => new ReplaySubject() }));
|
|
5480
|
+
? concat(of(localResponse), drainRemoteAfterLocal(bufferedTransport$, plan, replicaMutations))
|
|
5481
|
+
: drainRemoteNetworkFirst(bufferedTransport$, request, plan, fallback, replicaMutations))), { connector: () => new ReplaySubject() }));
|
|
5432
5482
|
}
|
|
5433
5483
|
/** Races a serialized local replica read against remote transport without allowing stale local data to follow remote. */
|
|
5434
5484
|
function readFastestFirst(request, plan, transport, fallback, errorHandler, replicaMutations) {
|
|
5435
5485
|
return defer(transport).pipe(materialize(), connect((bufferedTransport$) => {
|
|
5436
5486
|
const localDecision$ = resolveLocalAttempt(plan, errorHandler, replicaMutations).pipe(concatMap((localResponse) => localResponse
|
|
5437
|
-
? concat(of(localResponse), drainRemoteAfterLocal(bufferedTransport$, plan))
|
|
5438
|
-
: drainRemoteNetworkFirst(bufferedTransport$, request, plan, fallback)));
|
|
5487
|
+
? concat(of(localResponse), drainRemoteAfterLocal(bufferedTransport$, plan, replicaMutations))
|
|
5488
|
+
: drainRemoteNetworkFirst(bufferedTransport$, request, plan, fallback, replicaMutations)));
|
|
5439
5489
|
// Angular transport emits Sent/progress events before the response.
|
|
5440
5490
|
// They are not usable read results and therefore must not win the race.
|
|
5441
|
-
const remoteWinner$ = drainRemoteNetworkFirst(bufferedTransport$, request, plan, fallback).pipe(filter((event) => event instanceof HttpResponse),
|
|
5491
|
+
const remoteWinner$ = drainRemoteNetworkFirst(bufferedTransport$, request, plan, fallback, replicaMutations).pipe(filter((event) => event instanceof HttpResponse),
|
|
5442
5492
|
// A remote error is not a usable response. Keep it buffered until the
|
|
5443
5493
|
// local attempt decides whether it can satisfy the read.
|
|
5444
5494
|
catchError(() => NEVER));
|
|
@@ -5449,7 +5499,7 @@ function resolveLocalAttempt(plan, errorHandler, replicaMutations) {
|
|
|
5449
5499
|
return serializedLocalRead(plan, replicaMutations).pipe(catchError((localError) => {
|
|
5450
5500
|
errorHandler.handleError(localError);
|
|
5451
5501
|
return of(null);
|
|
5452
|
-
}), concatMap((local) => (local ? tryProjectLocal(local, plan, errorHandler) : of(null))), take(1));
|
|
5502
|
+
}), concatMap((local) => (local ? tryProjectLocal(local, plan, errorHandler, replicaMutations) : of(null))), take(1));
|
|
5453
5503
|
}
|
|
5454
5504
|
/** Skips a queued local read when its HTTP subscriber leaves before the lane opens. */
|
|
5455
5505
|
function serializedLocalRead(plan, replicaMutations) {
|
|
@@ -5471,26 +5521,29 @@ function serializedLocalRead(plan, replicaMutations) {
|
|
|
5471
5521
|
};
|
|
5472
5522
|
});
|
|
5473
5523
|
}
|
|
5474
|
-
function tryProjectLocal(cached, plan, errorHandler) {
|
|
5475
|
-
return emitTaggedLocalResponse(cached, plan).pipe(catchError((error) => {
|
|
5524
|
+
function tryProjectLocal(cached, plan, errorHandler, replicaMutations) {
|
|
5525
|
+
return emitTaggedLocalResponse(cached, plan, replicaMutations).pipe(catchError((error) => {
|
|
5476
5526
|
errorHandler.handleError(error);
|
|
5477
5527
|
return of(null);
|
|
5478
5528
|
}));
|
|
5479
5529
|
}
|
|
5480
|
-
function emitTaggedLocalResponse(cached, plan) {
|
|
5481
|
-
return projectReadResponse(cached.clone({ headers: cached.headers.set(OFFLINE_RESPONSE_HEADER, 'local') }), plan);
|
|
5530
|
+
function emitTaggedLocalResponse(cached, plan, replicaMutations) {
|
|
5531
|
+
return projectReadResponse(cached.clone({ headers: cached.headers.set(OFFLINE_RESPONSE_HEADER, 'local') }), plan, replicaMutations);
|
|
5482
5532
|
}
|
|
5483
|
-
function drainRemoteAfterLocal(bufferedTransport$, plan) {
|
|
5484
|
-
return bufferedTransport$.pipe(dematerialize(), catchError((error) => (isOfflineFallbackError(error) ? EMPTY : throwError(() => error))), concatMap((event) => projectReadResponse(event, plan)));
|
|
5533
|
+
function drainRemoteAfterLocal(bufferedTransport$, plan, replicaMutations) {
|
|
5534
|
+
return bufferedTransport$.pipe(dematerialize(), catchError((error) => (isOfflineFallbackError(error) ? EMPTY : throwError(() => error))), concatMap((event) => projectReadResponse(event, plan, replicaMutations)));
|
|
5485
5535
|
}
|
|
5486
|
-
function drainRemoteNetworkFirst(bufferedTransport$, request, plan, fallback) {
|
|
5487
|
-
return bufferedTransport$.pipe(dematerialize(), catchError((error) => fallback.handle(request, error, plan) ?? throwError(() => error)), concatMap((event) => projectReadResponse(event, plan)));
|
|
5536
|
+
function drainRemoteNetworkFirst(bufferedTransport$, request, plan, fallback, replicaMutations) {
|
|
5537
|
+
return bufferedTransport$.pipe(dematerialize(), catchError((error) => fallback.handle(request, error, plan) ?? throwError(() => error)), concatMap((event) => projectReadResponse(event, plan, replicaMutations)));
|
|
5488
5538
|
}
|
|
5489
|
-
function projectReadResponse(event, plan) {
|
|
5539
|
+
function projectReadResponse(event, plan, replicaMutations) {
|
|
5490
5540
|
if (!(event instanceof HttpResponse) || !plan.projectResponse)
|
|
5491
5541
|
return of(event);
|
|
5492
5542
|
const source = event.headers.get(OFFLINE_RESPONSE_HEADER) === 'local' ? 'local' : 'remote';
|
|
5493
|
-
|
|
5543
|
+
const projection = plan.serializeResponseProjection
|
|
5544
|
+
? replicaMutations.runSerializedRead(() => plan.projectResponse(event, source))
|
|
5545
|
+
: plan.projectResponse(event, source);
|
|
5546
|
+
return from(projection).pipe(map$1((response) => source === 'local' ? response.clone({ headers: response.headers.set(OFFLINE_RESPONSE_HEADER, 'local') }) : response));
|
|
5494
5547
|
}
|
|
5495
5548
|
function observeTransport(source, network) {
|
|
5496
5549
|
return source.pipe(tap({
|
|
@@ -6126,7 +6179,9 @@ class SqliteOfflineRepository {
|
|
|
6126
6179
|
ON CONFLICT(id) DO UPDATE SET version = excluded.version, schema_hash = excluded.schema_hash`, [version, schemaHash]);
|
|
6127
6180
|
}
|
|
6128
6181
|
async #nativeTransaction(databaseId, run) {
|
|
6129
|
-
await this.#sqlite.beginTransaction({ databaseId })
|
|
6182
|
+
await this.#sqlite.beginTransaction({ databaseId }).catch((error) => {
|
|
6183
|
+
throw normalizeOfflineReplicaTransientWriteError(error);
|
|
6184
|
+
});
|
|
6130
6185
|
const execute = async () => run();
|
|
6131
6186
|
return execute()
|
|
6132
6187
|
.then(async (result) => {
|
|
@@ -6134,13 +6189,14 @@ class SqliteOfflineRepository {
|
|
|
6134
6189
|
return result;
|
|
6135
6190
|
})
|
|
6136
6191
|
.catch(async (error) => {
|
|
6192
|
+
const normalizedError = normalizeOfflineReplicaTransientWriteError(error);
|
|
6137
6193
|
const rollback = await this.#sqlite.rollbackTransaction({ databaseId }).then(() => ({ status: 'fulfilled' }), (rollbackError) => ({ status: 'rejected', rollbackError }));
|
|
6138
6194
|
if (rollback.status === 'rejected') {
|
|
6139
|
-
throw new AggregateError([
|
|
6140
|
-
cause:
|
|
6195
|
+
throw new AggregateError([normalizedError, rollback.rollbackError], 'Offline SQLite transaction and rollback both failed.', {
|
|
6196
|
+
cause: normalizedError,
|
|
6141
6197
|
});
|
|
6142
6198
|
}
|
|
6143
|
-
throw
|
|
6199
|
+
throw normalizedError;
|
|
6144
6200
|
});
|
|
6145
6201
|
}
|
|
6146
6202
|
async #databaseConnection() {
|
|
@@ -6363,7 +6419,7 @@ class SqliteOfflineRepository {
|
|
|
6363
6419
|
await this.#execute(databaseId, 'UPDATE offline_metadata SET schema_version = schema_version WHERE id = 1');
|
|
6364
6420
|
const actual = await this.#dataVersion(databaseId);
|
|
6365
6421
|
if (actual !== expected) {
|
|
6366
|
-
throw new
|
|
6422
|
+
throw new OfflineReplicaTransientWriteError('concurrent_revision', 'Offline replica changed through another SQLite connection; retry the operation from fresh state.');
|
|
6367
6423
|
}
|
|
6368
6424
|
return run(databaseId);
|
|
6369
6425
|
});
|