@rdlabo/ionic-angular-kit 22.0.0-beta.pr96.shaa32019794c9b → 22.0.0-beta.pr97.shac93e32c6e176
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.
|
@@ -3138,7 +3138,7 @@ class OfflineSyncService {
|
|
|
3138
3138
|
const materializations = [];
|
|
3139
3139
|
for (const [index, entry] of prepared.entries()) {
|
|
3140
3140
|
this.#assertEnqueueScope(session, entry.request.scopeId);
|
|
3141
|
-
materializations.push(await this.#materializeEnqueue(session.userId, entry.request, replaced[index]));
|
|
3141
|
+
materializations.push(await this.#materializeEnqueue(session.userId, entry.request, repository, replaced[index]));
|
|
3142
3142
|
}
|
|
3143
3143
|
const retained = knownCommands.filter((command) => !replaced.some((item) => item.commandId === command.commandId));
|
|
3144
3144
|
this.#assertDistinctBatchFootprints(materializations, retained, true);
|
|
@@ -3181,8 +3181,8 @@ class OfflineSyncService {
|
|
|
3181
3181
|
async #enqueue(request, options, generation, replaced, repository = this.#repository) {
|
|
3182
3182
|
const session = await this.#beginEnqueueSession(generation);
|
|
3183
3183
|
this.#assertEnqueueScope(session, request.scopeId);
|
|
3184
|
-
const materialization = await this.#materializeEnqueue(session.userId, request, replaced);
|
|
3185
|
-
const currentCommands = await this.#commandsForUser(session.userId);
|
|
3184
|
+
const materialization = await this.#materializeEnqueue(session.userId, request, repository, replaced);
|
|
3185
|
+
const currentCommands = await this.#commandsForUser(session.userId, repository);
|
|
3186
3186
|
const retainedCommands = replaced ? currentCommands.filter((command) => command.commandId !== replaced.commandId) : currentCommands;
|
|
3187
3187
|
this.#assertDistinctBatchFootprints([materialization], retainedCommands);
|
|
3188
3188
|
await this.#assertOutboxCapacity(session.userId, [materialization.command], replaced ? [replaced.commandId] : undefined, currentCommands);
|
|
@@ -3194,14 +3194,14 @@ class OfflineSyncService {
|
|
|
3194
3194
|
throw new Error('Prepared offline batch must contain at least one command.');
|
|
3195
3195
|
}
|
|
3196
3196
|
const session = await this.#beginEnqueueSession(generation);
|
|
3197
|
-
const currentCommands = await this.#commandsForUser(session.userId);
|
|
3197
|
+
const currentCommands = await this.#commandsForUser(session.userId, repository);
|
|
3198
3198
|
this.#rememberCreatedAt(currentCommands);
|
|
3199
3199
|
const firstCreatedAt = Math.max(Date.now(), this.#lastCommandCreatedAt + 1);
|
|
3200
3200
|
this.#lastCommandCreatedAt = firstCreatedAt + prepared.length - 1;
|
|
3201
3201
|
const materializations = [];
|
|
3202
3202
|
for (const [index, entry] of prepared.entries()) {
|
|
3203
3203
|
this.#assertEnqueueScope(session, entry.request.scopeId);
|
|
3204
|
-
materializations.push(await this.#materializeEnqueue(session.userId, entry.request, undefined, firstCreatedAt + index));
|
|
3204
|
+
materializations.push(await this.#materializeEnqueue(session.userId, entry.request, repository, undefined, firstCreatedAt + index));
|
|
3205
3205
|
}
|
|
3206
3206
|
this.#assertDistinctBatchFootprints(materializations, currentCommands);
|
|
3207
3207
|
await this.#assertOutboxCapacity(session.userId, materializations.map((item) => item.command), undefined, currentCommands);
|
|
@@ -3230,11 +3230,11 @@ class OfflineSyncService {
|
|
|
3230
3230
|
}
|
|
3231
3231
|
this.noteScope({ userId: session.userId, scopeId });
|
|
3232
3232
|
}
|
|
3233
|
-
async #materializeEnqueue(userId, request, replaced, createdAt) {
|
|
3233
|
+
async #materializeEnqueue(userId, request, repository, replaced, createdAt) {
|
|
3234
3234
|
const scope = { userId, scopeId: request.scopeId };
|
|
3235
3235
|
this.noteScope(scope);
|
|
3236
3236
|
const commandIdentity = offlineCommandLookupIdentity(request.identity);
|
|
3237
|
-
const normalized = await this.#normalizeEnqueueRequest(scope, request, commandIdentity);
|
|
3237
|
+
const normalized = await this.#normalizeEnqueueRequest(scope, request, commandIdentity, repository);
|
|
3238
3238
|
const commandId = crypto.randomUUID();
|
|
3239
3239
|
const sourceKey = this.#hooks.entityType(request);
|
|
3240
3240
|
const localOnlyFootprint = this.#normalizedLocalOnlyFootprint(scope, request.localOnlyFootprint);
|
|
@@ -3253,7 +3253,7 @@ class OfflineSyncService {
|
|
|
3253
3253
|
state: 'pending',
|
|
3254
3254
|
attempts: 0,
|
|
3255
3255
|
retryAt: null,
|
|
3256
|
-
createdAt: replaced?.createdAt ?? createdAt ?? (await this.#nextCommandCreatedAt(userId)),
|
|
3256
|
+
createdAt: replaced?.createdAt ?? createdAt ?? (await this.#nextCommandCreatedAt(userId, repository)),
|
|
3257
3257
|
lastErrorCode: null,
|
|
3258
3258
|
};
|
|
3259
3259
|
if (localOnlyFootprint.length > 0)
|
|
@@ -3277,10 +3277,10 @@ class OfflineSyncService {
|
|
|
3277
3277
|
if (schema.identity.kind === 'naturalKey' && request.identity.kind !== 'natural') {
|
|
3278
3278
|
throw new Error(`Offline replica source "${entityType}" requires natural identity.`);
|
|
3279
3279
|
}
|
|
3280
|
-
if (request.replicaMutation === 'delete' && !
|
|
3280
|
+
if (request.replicaMutation === 'delete' && !repository.getReplicaRowIncludingPendingDelete) {
|
|
3281
3281
|
throw new Error('Offline repository does not support durable replica delete tombstones.');
|
|
3282
3282
|
}
|
|
3283
|
-
const existing = await this.#getReplicaRowForSync(scope, entityType, commandIdentity);
|
|
3283
|
+
const existing = await this.#getReplicaRowForSync(scope, entityType, commandIdentity, repository);
|
|
3284
3284
|
const generatedIdentity = request.identity.kind === 'generated' ? request.identity : null;
|
|
3285
3285
|
const initialRemoteId = this.#initialRemoteId(schema, existing?.identity.kind === 'generated' ? existing.identity.remoteId : null, generatedIdentity?.remoteId);
|
|
3286
3286
|
this.#assertRemoteIdHint(schema, existing?.identity.kind === 'generated' ? existing.identity.remoteId : null, generatedIdentity?.remoteIdHint);
|
|
@@ -3312,7 +3312,7 @@ class OfflineSyncService {
|
|
|
3312
3312
|
}
|
|
3313
3313
|
}
|
|
3314
3314
|
if (remoteIdentity !== null) {
|
|
3315
|
-
const mapped = await
|
|
3315
|
+
const mapped = await repository.getReplicaRowByRemoteIdentity(scope, entityType, remoteIdentity);
|
|
3316
3316
|
if (mapped !== null && !commandIdentityMatchesReplicaRow(schema, mapped, commandIdentity)) {
|
|
3317
3317
|
if ('remoteId' in remoteIdentity) {
|
|
3318
3318
|
throw new Error(`Offline replica remote id ${String(remoteIdentity.remoteId)} is already mapped to another row.`);
|
|
@@ -3404,7 +3404,7 @@ class OfflineSyncService {
|
|
|
3404
3404
|
putCommands: entries.map((entry) => entry.command),
|
|
3405
3405
|
removeCommandIds,
|
|
3406
3406
|
});
|
|
3407
|
-
await this.#refreshState().catch((error) => this.#reportError(error));
|
|
3407
|
+
await this.#refreshState(generation, repository).catch((error) => this.#reportError(error));
|
|
3408
3408
|
if (options.flush !== false && this.#canSynchronize())
|
|
3409
3409
|
this.#flushInBackground();
|
|
3410
3410
|
}
|
|
@@ -3899,10 +3899,10 @@ class OfflineSyncService {
|
|
|
3899
3899
|
}
|
|
3900
3900
|
}
|
|
3901
3901
|
}
|
|
3902
|
-
async #normalizeEnqueueRequest(scope, request, commandIdentity) {
|
|
3902
|
+
async #normalizeEnqueueRequest(scope, request, commandIdentity, repository) {
|
|
3903
3903
|
let baseRevision = request.baseRevision ?? null;
|
|
3904
3904
|
const sourceKey = this.#hooks.entityType(request);
|
|
3905
|
-
const row = await this.#getReplicaRowForSync(scope, sourceKey, commandIdentity);
|
|
3905
|
+
const row = await this.#getReplicaRowForSync(scope, sourceKey, commandIdentity, repository);
|
|
3906
3906
|
if (row?.serverRevision != null && row.serverRevision !== baseRevision) {
|
|
3907
3907
|
baseRevision = row.serverRevision;
|
|
3908
3908
|
}
|
|
@@ -3918,7 +3918,7 @@ class OfflineSyncService {
|
|
|
3918
3918
|
if (result.clearRemoteId === true && result.serverRevision !== undefined) {
|
|
3919
3919
|
throw new Error('Offline command cannot return serverRevision and clearRemoteId together.');
|
|
3920
3920
|
}
|
|
3921
|
-
const latestCommands = (await this.#readKnownCommands()).filter((candidate) => this.#aggregateKey(candidate) === this.#aggregateKey(command));
|
|
3921
|
+
const latestCommands = (await this.#readKnownCommands(repository)).filter((candidate) => this.#aggregateKey(candidate) === this.#aggregateKey(command));
|
|
3922
3922
|
const latestIndex = latestCommands.findIndex((candidate) => candidate.commandId === command.commandId);
|
|
3923
3923
|
if (latestIndex < 0)
|
|
3924
3924
|
return;
|
|
@@ -3929,7 +3929,7 @@ class OfflineSyncService {
|
|
|
3929
3929
|
: revision === undefined
|
|
3930
3930
|
? following
|
|
3931
3931
|
: following.map((item) => offlineCommandWithBaseRevision(item, revision));
|
|
3932
|
-
const current = await this.#rowForCommand(command);
|
|
3932
|
+
const current = await this.#rowForCommand(command, repository);
|
|
3933
3933
|
if (!this.#isCurrent(generation))
|
|
3934
3934
|
return;
|
|
3935
3935
|
if (!current) {
|
|
@@ -4269,8 +4269,8 @@ class OfflineSyncService {
|
|
|
4269
4269
|
this.#rememberCreatedAt(commands);
|
|
4270
4270
|
return commands;
|
|
4271
4271
|
}
|
|
4272
|
-
async #nextCommandCreatedAt(userId) {
|
|
4273
|
-
const commands = await this.#commandsForUser(userId);
|
|
4272
|
+
async #nextCommandCreatedAt(userId, repository = this.#repository) {
|
|
4273
|
+
const commands = await this.#commandsForUser(userId, repository);
|
|
4274
4274
|
this.#rememberCreatedAt(commands);
|
|
4275
4275
|
const createdAt = Math.max(Date.now(), this.#lastCommandCreatedAt + 1);
|
|
4276
4276
|
this.#lastCommandCreatedAt = createdAt;
|
|
@@ -5397,7 +5397,7 @@ const offlineInterceptor = (request, next) => {
|
|
|
5397
5397
|
if (plan.readStrategy === 'fastest-first') {
|
|
5398
5398
|
return readFastestFirst(request, plan, transport, fallback, inject(ErrorHandler), inject(OfflineReplicaMutationCoordinator));
|
|
5399
5399
|
}
|
|
5400
|
-
return readNetworkFirst(request, plan, transport, fallback);
|
|
5400
|
+
return readNetworkFirst(request, plan, transport, fallback, inject(OfflineReplicaMutationCoordinator));
|
|
5401
5401
|
}
|
|
5402
5402
|
if (LOCAL_FIRST_MUTATION_METHODS.has(request.method)) {
|
|
5403
5403
|
if (!inject(OFFLINE_MUTATION_PERSISTENCE_ENABLED)())
|
|
@@ -5409,8 +5409,8 @@ const offlineInterceptor = (request, next) => {
|
|
|
5409
5409
|
}
|
|
5410
5410
|
return transport();
|
|
5411
5411
|
};
|
|
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)));
|
|
5412
|
+
function readNetworkFirst(request, plan, transport, fallback, replicaMutations) {
|
|
5413
|
+
return defer(transport).pipe(catchError((error) => fallback.handle(request, error, plan) ?? throwError(() => error)), concatMap((event) => projectReadResponse(event, plan, replicaMutations)));
|
|
5414
5414
|
}
|
|
5415
5415
|
/**
|
|
5416
5416
|
* Stale-while-revalidate local-first GET handling.
|
|
@@ -5427,18 +5427,18 @@ function readNetworkFirst(request, plan, transport, fallback) {
|
|
|
5427
5427
|
*/
|
|
5428
5428
|
function readLocalFirst(request, plan, transport, fallback, errorHandler, replicaMutations) {
|
|
5429
5429
|
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() }));
|
|
5430
|
+
? concat(of(localResponse), drainRemoteAfterLocal(bufferedTransport$, plan, replicaMutations))
|
|
5431
|
+
: drainRemoteNetworkFirst(bufferedTransport$, request, plan, fallback, replicaMutations))), { connector: () => new ReplaySubject() }));
|
|
5432
5432
|
}
|
|
5433
5433
|
/** Races a serialized local replica read against remote transport without allowing stale local data to follow remote. */
|
|
5434
5434
|
function readFastestFirst(request, plan, transport, fallback, errorHandler, replicaMutations) {
|
|
5435
5435
|
return defer(transport).pipe(materialize(), connect((bufferedTransport$) => {
|
|
5436
5436
|
const localDecision$ = resolveLocalAttempt(plan, errorHandler, replicaMutations).pipe(concatMap((localResponse) => localResponse
|
|
5437
|
-
? concat(of(localResponse), drainRemoteAfterLocal(bufferedTransport$, plan))
|
|
5438
|
-
: drainRemoteNetworkFirst(bufferedTransport$, request, plan, fallback)));
|
|
5437
|
+
? concat(of(localResponse), drainRemoteAfterLocal(bufferedTransport$, plan, replicaMutations))
|
|
5438
|
+
: drainRemoteNetworkFirst(bufferedTransport$, request, plan, fallback, replicaMutations)));
|
|
5439
5439
|
// Angular transport emits Sent/progress events before the response.
|
|
5440
5440
|
// 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),
|
|
5441
|
+
const remoteWinner$ = drainRemoteNetworkFirst(bufferedTransport$, request, plan, fallback, replicaMutations).pipe(filter((event) => event instanceof HttpResponse),
|
|
5442
5442
|
// A remote error is not a usable response. Keep it buffered until the
|
|
5443
5443
|
// local attempt decides whether it can satisfy the read.
|
|
5444
5444
|
catchError(() => NEVER));
|
|
@@ -5449,7 +5449,7 @@ function resolveLocalAttempt(plan, errorHandler, replicaMutations) {
|
|
|
5449
5449
|
return serializedLocalRead(plan, replicaMutations).pipe(catchError((localError) => {
|
|
5450
5450
|
errorHandler.handleError(localError);
|
|
5451
5451
|
return of(null);
|
|
5452
|
-
}), concatMap((local) => (local ? tryProjectLocal(local, plan, errorHandler) : of(null))), take(1));
|
|
5452
|
+
}), concatMap((local) => (local ? tryProjectLocal(local, plan, errorHandler, replicaMutations) : of(null))), take(1));
|
|
5453
5453
|
}
|
|
5454
5454
|
/** Skips a queued local read when its HTTP subscriber leaves before the lane opens. */
|
|
5455
5455
|
function serializedLocalRead(plan, replicaMutations) {
|
|
@@ -5471,26 +5471,26 @@ function serializedLocalRead(plan, replicaMutations) {
|
|
|
5471
5471
|
};
|
|
5472
5472
|
});
|
|
5473
5473
|
}
|
|
5474
|
-
function tryProjectLocal(cached, plan, errorHandler) {
|
|
5475
|
-
return emitTaggedLocalResponse(cached, plan).pipe(catchError((error) => {
|
|
5474
|
+
function tryProjectLocal(cached, plan, errorHandler, replicaMutations) {
|
|
5475
|
+
return emitTaggedLocalResponse(cached, plan, replicaMutations).pipe(catchError((error) => {
|
|
5476
5476
|
errorHandler.handleError(error);
|
|
5477
5477
|
return of(null);
|
|
5478
5478
|
}));
|
|
5479
5479
|
}
|
|
5480
|
-
function emitTaggedLocalResponse(cached, plan) {
|
|
5481
|
-
return projectReadResponse(cached.clone({ headers: cached.headers.set(OFFLINE_RESPONSE_HEADER, 'local') }), plan);
|
|
5480
|
+
function emitTaggedLocalResponse(cached, plan, replicaMutations) {
|
|
5481
|
+
return projectReadResponse(cached.clone({ headers: cached.headers.set(OFFLINE_RESPONSE_HEADER, 'local') }), plan, replicaMutations);
|
|
5482
5482
|
}
|
|
5483
|
-
function drainRemoteAfterLocal(bufferedTransport$, plan) {
|
|
5484
|
-
return bufferedTransport$.pipe(dematerialize(), catchError((error) => (isOfflineFallbackError(error) ? EMPTY : throwError(() => error))), concatMap((event) => projectReadResponse(event, plan)));
|
|
5483
|
+
function drainRemoteAfterLocal(bufferedTransport$, plan, replicaMutations) {
|
|
5484
|
+
return bufferedTransport$.pipe(dematerialize(), catchError((error) => (isOfflineFallbackError(error) ? EMPTY : throwError(() => error))), concatMap((event) => projectReadResponse(event, plan, replicaMutations)));
|
|
5485
5485
|
}
|
|
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)));
|
|
5486
|
+
function drainRemoteNetworkFirst(bufferedTransport$, request, plan, fallback, replicaMutations) {
|
|
5487
|
+
return bufferedTransport$.pipe(dematerialize(), catchError((error) => fallback.handle(request, error, plan) ?? throwError(() => error)), concatMap((event) => projectReadResponse(event, plan, replicaMutations)));
|
|
5488
5488
|
}
|
|
5489
|
-
function projectReadResponse(event, plan) {
|
|
5489
|
+
function projectReadResponse(event, plan, replicaMutations) {
|
|
5490
5490
|
if (!(event instanceof HttpResponse) || !plan.projectResponse)
|
|
5491
5491
|
return of(event);
|
|
5492
5492
|
const source = event.headers.get(OFFLINE_RESPONSE_HEADER) === 'local' ? 'local' : 'remote';
|
|
5493
|
-
return from(plan.projectResponse(event, source)).pipe(map$1((response) => source === 'local' ? response.clone({ headers: response.headers.set(OFFLINE_RESPONSE_HEADER, 'local') }) : response));
|
|
5493
|
+
return from(replicaMutations.runSerializedRead(() => plan.projectResponse(event, source))).pipe(map$1((response) => source === 'local' ? response.clone({ headers: response.headers.set(OFFLINE_RESPONSE_HEADER, 'local') }) : response));
|
|
5494
5494
|
}
|
|
5495
5495
|
function observeTransport(source, network) {
|
|
5496
5496
|
return source.pipe(tap({
|