@rdlabo/ionic-angular-kit 21.5.2 → 21.5.4
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.
|
@@ -566,8 +566,6 @@ const METADATA_KEY = 'offline:metadata';
|
|
|
566
566
|
const SESSION_MANIFESTS_KEY = 'offline:session:manifests';
|
|
567
567
|
const ROWS_KEY = 'offline:replica:rows';
|
|
568
568
|
const CURSORS_KEY = 'offline:replica:cursors';
|
|
569
|
-
const LEGACY_ENTITIES_KEY = 'offline:business_cache:entities';
|
|
570
|
-
const LEGACY_QUERIES_KEY = 'offline:business_cache:queries';
|
|
571
569
|
const OUTBOX_KEY = 'offline:outbox:commands';
|
|
572
570
|
const REPLICA_TRANSACTION_KEY = 'offline:replica:transaction';
|
|
573
571
|
const REPLICA_SCHEMA_MIGRATION_KEY = 'offline:replica:schema-migration';
|
|
@@ -724,24 +722,8 @@ class IonicOfflineRepository {
|
|
|
724
722
|
async #migrate() {
|
|
725
723
|
const metadata = await this.#storage.get(METADATA_KEY);
|
|
726
724
|
if (metadata?.schemaVersion !== undefined && metadata.schemaVersion !== OFFLINE_SCHEMA_VERSION) {
|
|
727
|
-
|
|
728
|
-
this
|
|
729
|
-
this.#storage.remove(ROWS_KEY),
|
|
730
|
-
this.#storage.remove(CURSORS_KEY),
|
|
731
|
-
this.#storage.remove(LEGACY_ENTITIES_KEY),
|
|
732
|
-
this.#storage.remove(LEGACY_QUERIES_KEY),
|
|
733
|
-
this.#storage.remove(OUTBOX_KEY),
|
|
734
|
-
this.#storage.remove(REPLICA_SCHEMA_MIGRATION_KEY),
|
|
735
|
-
]);
|
|
736
|
-
await this.#storage.set(METADATA_KEY, {
|
|
737
|
-
schemaVersion: OFFLINE_SCHEMA_VERSION,
|
|
738
|
-
lastUserId: metadata.lastUserId ?? null,
|
|
739
|
-
replicaSchemaVersion: null,
|
|
740
|
-
replicaSchemaHash: null,
|
|
741
|
-
});
|
|
742
|
-
await this.#storage.remove(REPLICA_TRANSACTION_KEY);
|
|
743
|
-
await this.#initializeReplicaSchema(null, null);
|
|
744
|
-
return;
|
|
725
|
+
throw new Error(`Unsupported offline storage schema version ${metadata.schemaVersion}; expected ${OFFLINE_SCHEMA_VERSION}. ` +
|
|
726
|
+
'A lossless core schema migration is required before this database can be opened.');
|
|
745
727
|
}
|
|
746
728
|
const interruptedSchemaMigration = await this.#storage.get(REPLICA_SCHEMA_MIGRATION_KEY);
|
|
747
729
|
if (interruptedSchemaMigration) {
|
|
@@ -1198,12 +1180,19 @@ class OfflineReplicaPullService {
|
|
|
1198
1180
|
}
|
|
1199
1181
|
#collapseChanges(changes) {
|
|
1200
1182
|
const collapsed = new Map();
|
|
1201
|
-
for (const change of changes) {
|
|
1183
|
+
for (const [ordinal, change] of changes.entries()) {
|
|
1202
1184
|
const key = `${change.sourceKey}:${change.serverId}`;
|
|
1203
1185
|
const previous = collapsed.get(key);
|
|
1186
|
+
const acknowledgedCommandIds = [...new Set([...(previous?.acknowledgedCommandIds ?? []), ...(change.acknowledgedCommandIds ?? [])])];
|
|
1187
|
+
const acknowledgementOrdinals = { ...(previous?.acknowledgementOrdinals ?? {}) };
|
|
1188
|
+
for (const commandId of change.acknowledgedCommandIds ?? []) {
|
|
1189
|
+
acknowledgementOrdinals[commandId] = ordinal;
|
|
1190
|
+
}
|
|
1204
1191
|
collapsed.set(key, {
|
|
1205
1192
|
...change,
|
|
1206
|
-
acknowledgedCommandIds
|
|
1193
|
+
acknowledgedCommandIds,
|
|
1194
|
+
acknowledgementOrdinals,
|
|
1195
|
+
collapsedOrdinal: ordinal,
|
|
1207
1196
|
});
|
|
1208
1197
|
}
|
|
1209
1198
|
return [...collapsed.values()];
|
|
@@ -1217,9 +1206,13 @@ class OfflineReplicaPullService {
|
|
|
1217
1206
|
if (related.slice(0, lastAcknowledgedIndex + 1).some((command) => !acknowledgedIds.has(command.commandId))) {
|
|
1218
1207
|
throw new Error(`Replica acknowledgement skipped an earlier aggregate command.`);
|
|
1219
1208
|
}
|
|
1209
|
+
const lastAcknowledgedCommand = related[lastAcknowledgedIndex];
|
|
1210
|
+
const acknowledgementSuperseded = (change.acknowledgementOrdinals[lastAcknowledgedCommand.commandId] ?? -1) < change.collapsedOrdinal;
|
|
1220
1211
|
const following = related
|
|
1221
1212
|
.slice(lastAcknowledgedIndex + 1)
|
|
1222
|
-
.map((command) =>
|
|
1213
|
+
.map((command) => acknowledgementSuperseded
|
|
1214
|
+
? { ...command, state: 'conflict', retryAt: null, lastErrorCode: change.deleted ? 'remote_deleted' : 'remote_revision' }
|
|
1215
|
+
: this.#executor.withServerRevision(command, change.serverRevision));
|
|
1223
1216
|
for (const command of following)
|
|
1224
1217
|
putCommands.set(command.commandId, command);
|
|
1225
1218
|
for (const command of related.slice(0, lastAcknowledgedIndex + 1)) {
|
|
@@ -1247,7 +1240,7 @@ class OfflineReplicaPullService {
|
|
|
1247
1240
|
confirmedValues,
|
|
1248
1241
|
serverRevision: change.serverRevision,
|
|
1249
1242
|
fetchedAt: Date.now(),
|
|
1250
|
-
syncState: following.length > 0 ? 'pending' : 'confirmed',
|
|
1243
|
+
syncState: following.length > 0 ? (acknowledgementSuperseded ? 'conflict' : 'pending') : 'confirmed',
|
|
1251
1244
|
});
|
|
1252
1245
|
}
|
|
1253
1246
|
#assertServerIdAssignment(current, incoming) {
|
|
@@ -1534,7 +1527,8 @@ class OfflineSyncService {
|
|
|
1534
1527
|
return commands.length > 0 ? 'pending' : 'idle';
|
|
1535
1528
|
}, ...(ngDevMode ? [{ debugName: "syncState" }] : /* istanbul ignore next */ []));
|
|
1536
1529
|
effect(() => {
|
|
1537
|
-
|
|
1530
|
+
const connected = this.#network.connected();
|
|
1531
|
+
if (this.#initialized && connected)
|
|
1538
1532
|
this.#flushInBackground();
|
|
1539
1533
|
});
|
|
1540
1534
|
}
|
|
@@ -2540,8 +2534,10 @@ class SqliteOfflineRepository {
|
|
|
2540
2534
|
}
|
|
2541
2535
|
if (!commandColumns.some((column) => column['name'] === 'optimistic_value_json')) {
|
|
2542
2536
|
await this.#execute(databaseId, 'ALTER TABLE offline_sync_commands ADD COLUMN optimistic_value_json TEXT');
|
|
2543
|
-
await this.#execute(databaseId, 'UPDATE offline_sync_commands SET optimistic_value_json = payload_json');
|
|
2544
2537
|
}
|
|
2538
|
+
// Keep this repair outside the ADD-column branch so a process/database
|
|
2539
|
+
// failure after ALTER but before backfill is retried on every open.
|
|
2540
|
+
await this.#execute(databaseId, 'UPDATE offline_sync_commands SET optimistic_value_json = payload_json WHERE optimistic_value_json IS NULL');
|
|
2545
2541
|
await this.#execute(databaseId, `INSERT INTO offline_metadata (id, schema_version, last_user_id) VALUES (1, ?, NULL)
|
|
2546
2542
|
ON CONFLICT(id) DO UPDATE SET schema_version = excluded.schema_version`, [OFFLINE_SCHEMA_VERSION]);
|
|
2547
2543
|
await this.#initializeReplicaSchema(databaseId);
|