@rdlabo/ionic-angular-kit 21.5.35 → 21.5.36
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.
|
@@ -927,6 +927,7 @@ const OUTBOX_KEY = 'offline:outbox:commands';
|
|
|
927
927
|
const REPLICA_TRANSACTION_KEY = 'offline:replica:transaction';
|
|
928
928
|
const REPLICA_SCHEMA_MIGRATION_KEY = 'offline:replica:schema-migration';
|
|
929
929
|
const RECONCILIATION_SCOPES_KEY = 'offline:replica:reconciliation-scopes';
|
|
930
|
+
const PULL_ATTENTIONS_KEY = 'offline:replica:pull-attentions';
|
|
930
931
|
function compareOfflineCommands$1(left, right) {
|
|
931
932
|
return left.createdAt - right.createdAt || (left.commandId < right.commandId ? -1 : left.commandId > right.commandId ? 1 : 0);
|
|
932
933
|
}
|
|
@@ -991,6 +992,9 @@ class IonicOfflineRepository {
|
|
|
991
992
|
async getReconciliationScopes(userId) {
|
|
992
993
|
return this.#withCommittedRead(() => this.#readReconciliationScopes(userId));
|
|
993
994
|
}
|
|
995
|
+
async getPullAttentions(userId) {
|
|
996
|
+
return this.#withCommittedRead(() => this.#readPullAttentions(userId));
|
|
997
|
+
}
|
|
994
998
|
async getCommands(scope) {
|
|
995
999
|
return this.#withCommittedRead(() => this.#readCommands(scope));
|
|
996
1000
|
}
|
|
@@ -1060,6 +1064,12 @@ class IonicOfflineRepository {
|
|
|
1060
1064
|
const scopes = await this.#readRecord(RECONCILIATION_SCOPES_KEY);
|
|
1061
1065
|
return Object.values(scopes).filter((scope) => scope.userId === userId);
|
|
1062
1066
|
}
|
|
1067
|
+
async #readPullAttentions(userId) {
|
|
1068
|
+
const attentions = await this.#readRecord(PULL_ATTENTIONS_KEY);
|
|
1069
|
+
return Object.values(attentions)
|
|
1070
|
+
.filter((attention) => attention.userId === userId)
|
|
1071
|
+
.sort((left, right) => (left.scopeId < right.scopeId ? -1 : left.scopeId > right.scopeId ? 1 : 0));
|
|
1072
|
+
}
|
|
1063
1073
|
async #readCommands(scope) {
|
|
1064
1074
|
const commands = await this.#readRecord(OUTBOX_KEY);
|
|
1065
1075
|
return Object.values(commands)
|
|
@@ -1089,6 +1099,7 @@ class IonicOfflineRepository {
|
|
|
1089
1099
|
getReplicaRowByRemoteIdentity: (scope, sourceKey, identity) => this.#readReplicaRowByRemoteIdentity(scope, sourceKey, identity),
|
|
1090
1100
|
getReplicaCursor: (scope) => this.#readReplicaCursor(scope),
|
|
1091
1101
|
getReconciliationScopes: (userId) => this.#readReconciliationScopes(userId),
|
|
1102
|
+
getPullAttentions: (userId) => this.#readPullAttentions(userId),
|
|
1092
1103
|
getCommands: (scope) => this.#readCommands(scope),
|
|
1093
1104
|
getCommandsForUser: (userId) => this.#readCommandsForUser(userId),
|
|
1094
1105
|
};
|
|
@@ -1141,6 +1152,20 @@ class IonicOfflineRepository {
|
|
|
1141
1152
|
return commands;
|
|
1142
1153
|
});
|
|
1143
1154
|
}
|
|
1155
|
+
async putPullAttention(attention) {
|
|
1156
|
+
await this.initialize();
|
|
1157
|
+
await this.#mutateRecord(PULL_ATTENTIONS_KEY, (attentions) => {
|
|
1158
|
+
attentions[this.#cursorKey(attention)] = attention;
|
|
1159
|
+
return attentions;
|
|
1160
|
+
});
|
|
1161
|
+
}
|
|
1162
|
+
async removePullAttention(scope) {
|
|
1163
|
+
await this.initialize();
|
|
1164
|
+
await this.#mutateRecord(PULL_ATTENTIONS_KEY, (attentions) => {
|
|
1165
|
+
delete attentions[this.#cursorKey(scope)];
|
|
1166
|
+
return attentions;
|
|
1167
|
+
});
|
|
1168
|
+
}
|
|
1144
1169
|
async clearUser(userId) {
|
|
1145
1170
|
await this.initialize();
|
|
1146
1171
|
await this.#enqueueWrite(async () => {
|
|
@@ -1154,6 +1179,7 @@ class IonicOfflineRepository {
|
|
|
1154
1179
|
this.#filterRecordNow(OUTBOX_KEY, (value) => value.userId !== userId),
|
|
1155
1180
|
this.#filterRecordNow(CURSORS_KEY, (_value, key) => !key.startsWith(`${canonicalOfflinePrincipalId(userId)}:`)),
|
|
1156
1181
|
this.#filterRecordNow(RECONCILIATION_SCOPES_KEY, (value) => value.userId !== userId),
|
|
1182
|
+
this.#filterRecordNow(PULL_ATTENTIONS_KEY, (value) => value.userId !== userId),
|
|
1157
1183
|
]);
|
|
1158
1184
|
const metadata = await this.#metadata();
|
|
1159
1185
|
if (metadata.lastUserId === userId) {
|
|
@@ -1181,6 +1207,7 @@ class IonicOfflineRepository {
|
|
|
1181
1207
|
}),
|
|
1182
1208
|
this.#filterRecordNow(CURSORS_KEY, (_value, key) => key !== this.#cursorKey(scope)),
|
|
1183
1209
|
this.#filterRecordNow(RECONCILIATION_SCOPES_KEY, (value) => !belongsToGroup(value)),
|
|
1210
|
+
this.#filterRecordNow(PULL_ATTENTIONS_KEY, (value) => !belongsToGroup(value)),
|
|
1184
1211
|
]);
|
|
1185
1212
|
});
|
|
1186
1213
|
}
|
|
@@ -1341,11 +1368,12 @@ class IonicOfflineRepository {
|
|
|
1341
1368
|
await this.#assertReplicaSchemaLocked();
|
|
1342
1369
|
for (const row of transaction.putRows ?? [])
|
|
1343
1370
|
this.#validateReplicaRow(row);
|
|
1344
|
-
const [rows, commands, cursors, reconciliationScopes] = await Promise.all([
|
|
1371
|
+
const [rows, commands, cursors, reconciliationScopes, pullAttentions] = await Promise.all([
|
|
1345
1372
|
this.#readRecord(ROWS_KEY),
|
|
1346
1373
|
this.#readRecord(OUTBOX_KEY),
|
|
1347
1374
|
this.#readRecord(CURSORS_KEY),
|
|
1348
1375
|
this.#readRecord(RECONCILIATION_SCOPES_KEY),
|
|
1376
|
+
this.#readRecord(PULL_ATTENTIONS_KEY),
|
|
1349
1377
|
]);
|
|
1350
1378
|
const identityCheckRows = { ...rows };
|
|
1351
1379
|
const releases = new Map();
|
|
@@ -1402,11 +1430,18 @@ class IonicOfflineRepository {
|
|
|
1402
1430
|
for (const scope of transaction.removeReconciliationScopes ?? []) {
|
|
1403
1431
|
delete reconciliationScopes[this.#cursorKey(scope)];
|
|
1404
1432
|
}
|
|
1433
|
+
for (const attention of transaction.putPullAttentions ?? []) {
|
|
1434
|
+
pullAttentions[this.#cursorKey(attention)] = attention;
|
|
1435
|
+
}
|
|
1436
|
+
for (const scope of transaction.removePullAttentions ?? []) {
|
|
1437
|
+
delete pullAttentions[this.#cursorKey(scope)];
|
|
1438
|
+
}
|
|
1405
1439
|
await Promise.all([
|
|
1406
1440
|
this.#storage.set(ROWS_KEY, rows),
|
|
1407
1441
|
this.#storage.set(OUTBOX_KEY, commands),
|
|
1408
1442
|
this.#storage.set(CURSORS_KEY, cursors),
|
|
1409
1443
|
this.#storage.set(RECONCILIATION_SCOPES_KEY, reconciliationScopes),
|
|
1444
|
+
this.#storage.set(PULL_ATTENTIONS_KEY, pullAttentions),
|
|
1410
1445
|
]);
|
|
1411
1446
|
await this.#writeAffectedRowPartitions(rows, transaction);
|
|
1412
1447
|
await this.#storage.remove(REPLICA_TRANSACTION_KEY);
|
|
@@ -2508,6 +2543,7 @@ class OfflineSyncService {
|
|
|
2508
2543
|
#errorHandler;
|
|
2509
2544
|
#retryRandom;
|
|
2510
2545
|
#commands;
|
|
2546
|
+
#pullAttentions;
|
|
2511
2547
|
#knownScopes;
|
|
2512
2548
|
/** ACKed scopes whose authoritative post-send pull has not completed yet. */
|
|
2513
2549
|
#pendingPullScopes;
|
|
@@ -2536,6 +2572,7 @@ class OfflineSyncService {
|
|
|
2536
2572
|
this.#errorHandler = inject(ErrorHandler);
|
|
2537
2573
|
this.#retryRandom = inject(OFFLINE_RETRY_RANDOM);
|
|
2538
2574
|
this.#commands = signal([], ...(ngDevMode ? [{ debugName: "#commands" }] : /* istanbul ignore next */ []));
|
|
2575
|
+
this.#pullAttentions = signal([], ...(ngDevMode ? [{ debugName: "#pullAttentions" }] : /* istanbul ignore next */ []));
|
|
2539
2576
|
this.#knownScopes = new Map();
|
|
2540
2577
|
/** ACKed scopes whose authoritative post-send pull has not completed yet. */
|
|
2541
2578
|
this.#pendingPullScopes = new Map();
|
|
@@ -2555,7 +2592,11 @@ class OfflineSyncService {
|
|
|
2555
2592
|
this.pendingCommands = this.#commands.asReadonly();
|
|
2556
2593
|
this.pendingCount = computed(() => this.pendingCommands().length, ...(ngDevMode ? [{ debugName: "pendingCount" }] : /* istanbul ignore next */ []));
|
|
2557
2594
|
this.conflicts = computed(() => this.#commands().filter((command) => command.state === 'conflict'), ...(ngDevMode ? [{ debugName: "conflicts" }] : /* istanbul ignore next */ []));
|
|
2595
|
+
/** Durable fatal-pull attentions for the active principal, restored across restart. */
|
|
2596
|
+
this.pullAttentions = this.#pullAttentions.asReadonly();
|
|
2558
2597
|
this.syncState = computed(() => {
|
|
2598
|
+
if (this.#pullAttentions().length > 0)
|
|
2599
|
+
return 'attention';
|
|
2559
2600
|
const commands = this.#commands();
|
|
2560
2601
|
if (commands.some((command) => ['blocked_auth', 'rejected', 'conflict'].includes(command.state)))
|
|
2561
2602
|
return 'attention';
|
|
@@ -2622,6 +2663,7 @@ class OfflineSyncService {
|
|
|
2622
2663
|
this.#knownScopes.clear();
|
|
2623
2664
|
this.#pendingPullScopes.clear();
|
|
2624
2665
|
this.#commands.set([]);
|
|
2666
|
+
this.#pullAttentions.set([]);
|
|
2625
2667
|
this.#scheduleRetry(null);
|
|
2626
2668
|
}
|
|
2627
2669
|
/** Synchronously invalidate in-flight enqueue and transport work owned by the current session. */
|
|
@@ -3217,6 +3259,7 @@ class OfflineSyncService {
|
|
|
3217
3259
|
if (this.#isFatalPullFailure(error)) {
|
|
3218
3260
|
// Auth/upgrade-driven recovery only: stop remaining scopes immediately.
|
|
3219
3261
|
fatalPullFailure = fatalPullFailure ?? error;
|
|
3262
|
+
await this.#persistFatalPullAttentions(error, scope, pullScopes, generation);
|
|
3220
3263
|
break;
|
|
3221
3264
|
}
|
|
3222
3265
|
if (this.#pendingPullScopes.has(this.#scopeKey(scope))) {
|
|
@@ -3259,7 +3302,8 @@ class OfflineSyncService {
|
|
|
3259
3302
|
// Fatal pre-pull skips pending post-pulls; recovery is auth/upgrade-driven, not timer retry.
|
|
3260
3303
|
// Fatal post-send pull stops remaining pending scopes the same way (ACK preserved, no resend).
|
|
3261
3304
|
if (fatalPullFailure === null) {
|
|
3262
|
-
|
|
3305
|
+
const postPullScopes = [...this.#pendingPullScopes.values()];
|
|
3306
|
+
for (const scope of postPullScopes) {
|
|
3263
3307
|
if (!this.#isCurrent(generation) || !this.#network.connected())
|
|
3264
3308
|
break;
|
|
3265
3309
|
try {
|
|
@@ -3272,6 +3316,7 @@ class OfflineSyncService {
|
|
|
3272
3316
|
catch (error) {
|
|
3273
3317
|
if (this.#isFatalPullFailure(error)) {
|
|
3274
3318
|
fatalPullFailure = fatalPullFailure ?? error;
|
|
3319
|
+
await this.#persistFatalPullAttentions(error, scope, postPullScopes, generation);
|
|
3275
3320
|
break;
|
|
3276
3321
|
}
|
|
3277
3322
|
postPullFailures.push(error);
|
|
@@ -3308,14 +3353,59 @@ class OfflineSyncService {
|
|
|
3308
3353
|
return true;
|
|
3309
3354
|
return error instanceof OfflineReplicaSchemaMismatchError;
|
|
3310
3355
|
}
|
|
3356
|
+
#pullAttentionReason(error) {
|
|
3357
|
+
if (error instanceof OfflineReplicaSchemaMismatchError)
|
|
3358
|
+
return 'schema_upgrade_required';
|
|
3359
|
+
const status = this.#errorStatus(error);
|
|
3360
|
+
if (status === 409)
|
|
3361
|
+
return 'schema_upgrade_required';
|
|
3362
|
+
if (status === 401 || status === 403)
|
|
3363
|
+
return 'authorization_required';
|
|
3364
|
+
return null;
|
|
3365
|
+
}
|
|
3366
|
+
/**
|
|
3367
|
+
* Persists durable pull attentions for a current-generation fatal pull.
|
|
3368
|
+
* Schema/409 marks all attempted pull scopes; 401 marks every known principal scope;
|
|
3369
|
+
* 403 marks only the failing scope. Stale generations must not mutate a newer session.
|
|
3370
|
+
*/
|
|
3371
|
+
async #persistFatalPullAttentions(error, failingScope, attemptedScopes, generation) {
|
|
3372
|
+
if (!this.#isCurrent(generation))
|
|
3373
|
+
return;
|
|
3374
|
+
const reason = this.#pullAttentionReason(error);
|
|
3375
|
+
if (reason === null)
|
|
3376
|
+
return;
|
|
3377
|
+
const status = this.#errorStatus(error);
|
|
3378
|
+
// Snapshot synchronously before any await so a concurrent session switch cannot retarget scopes.
|
|
3379
|
+
const scoped = status === 403
|
|
3380
|
+
? [failingScope]
|
|
3381
|
+
: status === 401
|
|
3382
|
+
? [...this.#knownScopes.values()].filter((scope) => scope.userId === failingScope.userId)
|
|
3383
|
+
: attemptedScopes.filter((scope) => scope.userId === failingScope.userId);
|
|
3384
|
+
const scopes = scoped.length > 0 ? scoped : [failingScope];
|
|
3385
|
+
const attentions = scopes.map((scope) => {
|
|
3386
|
+
const attention = {
|
|
3387
|
+
userId: scope.userId,
|
|
3388
|
+
scopeId: scope.scopeId,
|
|
3389
|
+
reason,
|
|
3390
|
+
};
|
|
3391
|
+
if (status > 0)
|
|
3392
|
+
attention.status = status;
|
|
3393
|
+
return attention;
|
|
3394
|
+
});
|
|
3395
|
+
if (!this.#isCurrent(generation))
|
|
3396
|
+
return;
|
|
3397
|
+
await this.#repository.transactReplica({ putPullAttentions: attentions });
|
|
3398
|
+
}
|
|
3311
3399
|
#setForegroundScopePolicy(foregroundScopeIds) {
|
|
3312
3400
|
this.#foregroundScopePolicy = foregroundScopeIds !== undefined ? foregroundScopeIds : null;
|
|
3313
3401
|
}
|
|
3314
3402
|
#scopesForPartialPull(foregroundScopeIds, commands) {
|
|
3315
3403
|
const foregroundScopeSet = new Set(foregroundScopeIds);
|
|
3316
3404
|
const outboxScopeKeys = new Set(commands.map((command) => this.#scopeKey({ userId: command.userId, scopeId: command.scopeId })));
|
|
3405
|
+
const attentionScopeKeys = new Set(this.#pullAttentions().map((attention) => this.#scopeKey(attention)));
|
|
3317
3406
|
return [...this.#knownScopes.values()].filter((scope) => foregroundScopeSet.has(scope.scopeId) ||
|
|
3318
3407
|
outboxScopeKeys.has(this.#scopeKey(scope)) ||
|
|
3408
|
+
attentionScopeKeys.has(this.#scopeKey(scope)) ||
|
|
3319
3409
|
this.#pendingPullScopes.has(this.#scopeKey(scope)));
|
|
3320
3410
|
}
|
|
3321
3411
|
#eligibleAggregateGroups(commands) {
|
|
@@ -3763,6 +3853,7 @@ class OfflineSyncService {
|
|
|
3763
3853
|
for (const scope of session.scopes)
|
|
3764
3854
|
this.#knownScopes.set(this.#scopeKey(scope), scope);
|
|
3765
3855
|
await this.#restorePendingPullScopes(session.userId, generation);
|
|
3856
|
+
await this.#prunePullAttentions(session.userId, generation);
|
|
3766
3857
|
return true;
|
|
3767
3858
|
}
|
|
3768
3859
|
async #discoverLocalScopes(generation = this.#generation) {
|
|
@@ -3772,6 +3863,7 @@ class OfflineSyncService {
|
|
|
3772
3863
|
if (!session) {
|
|
3773
3864
|
this.#activeUserId = null;
|
|
3774
3865
|
this.#knownScopes.clear();
|
|
3866
|
+
this.#pullAttentions.set([]);
|
|
3775
3867
|
return true;
|
|
3776
3868
|
}
|
|
3777
3869
|
this.#assertSessionPrincipalBoundary(session);
|
|
@@ -3780,6 +3872,7 @@ class OfflineSyncService {
|
|
|
3780
3872
|
for (const scope of session.scopes)
|
|
3781
3873
|
this.#knownScopes.set(this.#scopeKey(scope), scope);
|
|
3782
3874
|
await this.#restorePendingPullScopes(session.userId, generation);
|
|
3875
|
+
await this.#prunePullAttentions(session.userId, generation);
|
|
3783
3876
|
return true;
|
|
3784
3877
|
}
|
|
3785
3878
|
#getLocalSession() {
|
|
@@ -3790,6 +3883,7 @@ class OfflineSyncService {
|
|
|
3790
3883
|
return;
|
|
3791
3884
|
this.#knownScopes.clear();
|
|
3792
3885
|
this.#pendingPullScopes.clear();
|
|
3886
|
+
this.#pullAttentions.set([]);
|
|
3793
3887
|
this.#activeUserId = userId;
|
|
3794
3888
|
this.#lastCommandCreatedAt = 0;
|
|
3795
3889
|
}
|
|
@@ -3821,9 +3915,11 @@ class OfflineSyncService {
|
|
|
3821
3915
|
}
|
|
3822
3916
|
async #refreshState(generation = this.#generation) {
|
|
3823
3917
|
const commands = await this.#readKnownCommands();
|
|
3918
|
+
const attentions = this.#activeUserId !== null && this.#repository.getPullAttentions ? await this.#repository.getPullAttentions(this.#activeUserId) : [];
|
|
3824
3919
|
if (!this.#isCurrent(generation))
|
|
3825
3920
|
return;
|
|
3826
3921
|
this.#commands.set(commands);
|
|
3922
|
+
this.#pullAttentions.set(attentions);
|
|
3827
3923
|
const nextRetry = commands
|
|
3828
3924
|
.filter((command) => command.state === 'retry_wait' && command.retryAt !== null)
|
|
3829
3925
|
.reduce((earliest, command) => Math.min(earliest ?? command.retryAt, command.retryAt), null);
|
|
@@ -3916,10 +4012,25 @@ class OfflineSyncService {
|
|
|
3916
4012
|
await this.#repository.transactReplica({ removeReconciliationScopes: revoked });
|
|
3917
4013
|
}
|
|
3918
4014
|
}
|
|
4015
|
+
async #prunePullAttentions(userId, generation) {
|
|
4016
|
+
if (!this.#repository.getPullAttentions)
|
|
4017
|
+
return;
|
|
4018
|
+
const attentions = await this.#repository.getPullAttentions(userId);
|
|
4019
|
+
if (!this.#isCurrent(generation) || this.#activeUserId !== userId)
|
|
4020
|
+
return;
|
|
4021
|
+
const currentKeys = new Set(this.#knownScopes.keys());
|
|
4022
|
+
const revoked = attentions.filter((attention) => !currentKeys.has(this.#scopeKey(attention)));
|
|
4023
|
+
if (revoked.length > 0) {
|
|
4024
|
+
await this.#repository.transactReplica({ removePullAttentions: revoked });
|
|
4025
|
+
}
|
|
4026
|
+
}
|
|
3919
4027
|
async #markScopeReconciled(scope, generation) {
|
|
3920
4028
|
if (!this.#isCurrent(generation))
|
|
3921
4029
|
return;
|
|
3922
|
-
await this.#repository.transactReplica({
|
|
4030
|
+
await this.#repository.transactReplica({
|
|
4031
|
+
removeReconciliationScopes: [scope],
|
|
4032
|
+
removePullAttentions: [scope],
|
|
4033
|
+
});
|
|
3923
4034
|
if (!this.#isCurrent(generation))
|
|
3924
4035
|
return;
|
|
3925
4036
|
this.#pendingPullScopes.delete(this.#scopeKey(scope));
|
|
@@ -4424,6 +4535,13 @@ const SCHEMA = [
|
|
|
4424
4535
|
user_id TEXT NOT NULL,
|
|
4425
4536
|
scope_id TEXT NOT NULL,
|
|
4426
4537
|
PRIMARY KEY (user_id, scope_id)
|
|
4538
|
+
)`,
|
|
4539
|
+
`CREATE TABLE IF NOT EXISTS offline_pull_attentions (
|
|
4540
|
+
user_id TEXT NOT NULL,
|
|
4541
|
+
scope_id TEXT NOT NULL,
|
|
4542
|
+
reason TEXT NOT NULL,
|
|
4543
|
+
status INTEGER,
|
|
4544
|
+
PRIMARY KEY (user_id, scope_id)
|
|
4427
4545
|
)`,
|
|
4428
4546
|
];
|
|
4429
4547
|
/** Native iOS/Android repository backed by encrypted `@capacitor-community/sqlite`. */
|
|
@@ -4483,6 +4601,9 @@ class SqliteOfflineRepository {
|
|
|
4483
4601
|
async getReconciliationScopes(userId) {
|
|
4484
4602
|
return this.#withCommittedRead(() => this.#readReconciliationScopes(userId));
|
|
4485
4603
|
}
|
|
4604
|
+
async getPullAttentions(userId) {
|
|
4605
|
+
return this.#withCommittedRead(() => this.#readPullAttentions(userId));
|
|
4606
|
+
}
|
|
4486
4607
|
async getCommands(scope) {
|
|
4487
4608
|
return this.#withCommittedRead(() => this.#readCommands(scope));
|
|
4488
4609
|
}
|
|
@@ -4501,6 +4622,21 @@ class SqliteOfflineRepository {
|
|
|
4501
4622
|
async removeCommand(commandId) {
|
|
4502
4623
|
await this.#write('DELETE FROM offline_sync_commands WHERE command_id = ?', [commandId]);
|
|
4503
4624
|
}
|
|
4625
|
+
async putPullAttention(attention) {
|
|
4626
|
+
await this.#write(`INSERT INTO offline_pull_attentions (user_id, scope_id, reason, status) VALUES (?, ?, ?, ?)
|
|
4627
|
+
ON CONFLICT(user_id, scope_id) DO UPDATE SET reason = excluded.reason, status = excluded.status`, [
|
|
4628
|
+
canonicalOfflinePrincipalId(attention.userId),
|
|
4629
|
+
attention.scopeId,
|
|
4630
|
+
attention.reason,
|
|
4631
|
+
attention.status === undefined ? null : attention.status,
|
|
4632
|
+
]);
|
|
4633
|
+
}
|
|
4634
|
+
async removePullAttention(scope) {
|
|
4635
|
+
await this.#write('DELETE FROM offline_pull_attentions WHERE user_id = ? AND scope_id = ?', [
|
|
4636
|
+
canonicalOfflinePrincipalId(scope.userId),
|
|
4637
|
+
scope.scopeId,
|
|
4638
|
+
]);
|
|
4639
|
+
}
|
|
4504
4640
|
async clearUser(userId) {
|
|
4505
4641
|
await this.#transaction(async (database) => {
|
|
4506
4642
|
const principal = canonicalOfflinePrincipalId(userId);
|
|
@@ -4508,6 +4644,7 @@ class SqliteOfflineRepository {
|
|
|
4508
4644
|
await this.#execute(database, 'DELETE FROM offline_sync_commands WHERE user_id = ?', [principal]);
|
|
4509
4645
|
await this.#execute(database, 'DELETE FROM offline_replica_cursors WHERE user_id = ?', [principal]);
|
|
4510
4646
|
await this.#execute(database, 'DELETE FROM offline_reconciliation_scopes WHERE user_id = ?', [principal]);
|
|
4647
|
+
await this.#execute(database, 'DELETE FROM offline_pull_attentions WHERE user_id = ?', [principal]);
|
|
4511
4648
|
for (const entity of this.#options.replicaSchema.entities) {
|
|
4512
4649
|
await this.#execute(database, `DELETE FROM ${entity.tableName} WHERE _offline_user_id = ?`, [principal]);
|
|
4513
4650
|
}
|
|
@@ -4526,6 +4663,7 @@ class SqliteOfflineRepository {
|
|
|
4526
4663
|
}
|
|
4527
4664
|
await this.#execute(database, 'DELETE FROM offline_replica_cursors WHERE user_id = ? AND scope_id = ?', values);
|
|
4528
4665
|
await this.#execute(database, 'DELETE FROM offline_reconciliation_scopes WHERE user_id = ? AND scope_id = ?', values);
|
|
4666
|
+
await this.#execute(database, 'DELETE FROM offline_pull_attentions WHERE user_id = ? AND scope_id = ?', values);
|
|
4529
4667
|
for (const entity of this.#options.replicaSchema.entities) {
|
|
4530
4668
|
if (entity.scope !== 'partition')
|
|
4531
4669
|
continue;
|
|
@@ -4576,6 +4714,21 @@ class SqliteOfflineRepository {
|
|
|
4576
4714
|
scope.scopeId,
|
|
4577
4715
|
]);
|
|
4578
4716
|
}
|
|
4717
|
+
for (const attention of transaction.putPullAttentions ?? []) {
|
|
4718
|
+
await this.#execute(databaseId, `INSERT INTO offline_pull_attentions (user_id, scope_id, reason, status) VALUES (?, ?, ?, ?)
|
|
4719
|
+
ON CONFLICT(user_id, scope_id) DO UPDATE SET reason = excluded.reason, status = excluded.status`, [
|
|
4720
|
+
canonicalOfflinePrincipalId(attention.userId),
|
|
4721
|
+
attention.scopeId,
|
|
4722
|
+
attention.reason,
|
|
4723
|
+
attention.status === undefined ? null : attention.status,
|
|
4724
|
+
]);
|
|
4725
|
+
}
|
|
4726
|
+
for (const scope of transaction.removePullAttentions ?? []) {
|
|
4727
|
+
await this.#execute(databaseId, 'DELETE FROM offline_pull_attentions WHERE user_id = ? AND scope_id = ?', [
|
|
4728
|
+
canonicalOfflinePrincipalId(scope.userId),
|
|
4729
|
+
scope.scopeId,
|
|
4730
|
+
]);
|
|
4731
|
+
}
|
|
4579
4732
|
});
|
|
4580
4733
|
}
|
|
4581
4734
|
async #open() {
|
|
@@ -4752,6 +4905,22 @@ class SqliteOfflineRepository {
|
|
|
4752
4905
|
]);
|
|
4753
4906
|
return rows.map((row) => ({ userId, scopeId: this.#string(row['scope_id']) }));
|
|
4754
4907
|
}
|
|
4908
|
+
async #readPullAttentions(userId) {
|
|
4909
|
+
const rows = await this.#query('SELECT scope_id, reason, status FROM offline_pull_attentions WHERE user_id = ? ORDER BY scope_id', [
|
|
4910
|
+
canonicalOfflinePrincipalId(userId),
|
|
4911
|
+
]);
|
|
4912
|
+
return rows.map((row) => {
|
|
4913
|
+
const status = row['status'];
|
|
4914
|
+
const attention = {
|
|
4915
|
+
userId,
|
|
4916
|
+
scopeId: this.#string(row['scope_id']),
|
|
4917
|
+
reason: this.#string(row['reason']),
|
|
4918
|
+
};
|
|
4919
|
+
if (status !== null && status !== undefined)
|
|
4920
|
+
attention.status = this.#number(status);
|
|
4921
|
+
return attention;
|
|
4922
|
+
});
|
|
4923
|
+
}
|
|
4755
4924
|
async #readCommands(scope) {
|
|
4756
4925
|
const rows = await this.#query('SELECT * FROM offline_sync_commands WHERE user_id = ? AND scope_id = ? ORDER BY created_at ASC, command_id ASC', [canonicalOfflinePrincipalId(scope.userId), scope.scopeId]);
|
|
4757
4926
|
return rows.map((row) => this.#command(row));
|
|
@@ -4777,6 +4946,7 @@ class SqliteOfflineRepository {
|
|
|
4777
4946
|
getReplicaRowByRemoteIdentity: (scope, sourceKey, identity) => this.#readReplicaRowByRemoteIdentity(scope, sourceKey, identity),
|
|
4778
4947
|
getReplicaCursor: (scope) => this.#readReplicaCursor(scope),
|
|
4779
4948
|
getReconciliationScopes: (userId) => this.#readReconciliationScopes(userId),
|
|
4949
|
+
getPullAttentions: (userId) => this.#readPullAttentions(userId),
|
|
4780
4950
|
getCommands: (scope) => this.#readCommands(scope),
|
|
4781
4951
|
getCommandsForUser: (userId) => this.#readCommandsForUser(userId),
|
|
4782
4952
|
};
|