@rdlabo/ionic-angular-kit 22.0.0-beta.pr97.shac93e32c6e176 → 22.0.0-beta.pr97.shaea83d9a904af
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;
|
|
@@ -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))
|
|
@@ -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.');
|
|
@@ -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
|
}
|
|
@@ -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 {
|
|
@@ -5490,7 +5540,10 @@ 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
|
});
|