@rdlabo/ionic-angular-kit 21.5.29 → 21.5.30

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.
@@ -2458,13 +2458,18 @@ class OfflineSyncService {
2458
2458
  throw new Error('Prepared offline batch must contain at least one command.');
2459
2459
  }
2460
2460
  const session = await this.#beginEnqueueSession(generation);
2461
+ const currentCommands = await this.#commandsForUser(session.userId);
2462
+ this.#rememberCreatedAt(currentCommands);
2463
+ const firstCreatedAt = Math.max(Date.now(), this.#lastCommandCreatedAt + 1);
2464
+ this.#lastCommandCreatedAt = firstCreatedAt + prepared.length - 1;
2461
2465
  const materializations = [];
2462
- for (const entry of prepared) {
2466
+ for (const [index, entry] of prepared.entries()) {
2463
2467
  this.#assertEnqueueScope(session, entry.request.scopeId);
2464
- materializations.push(await this.#materializeEnqueue(session.userId, entry.request, entry.replicaTransaction));
2468
+ materializations.push(await this.#materializeEnqueue(session.userId, entry.request, entry.replicaTransaction, undefined, firstCreatedAt + index));
2465
2469
  }
2466
2470
  this.#assertDistinctBatchFootprints(materializations);
2467
- await this.#assertOutboxCapacity(session.userId, materializations.map((item) => item.command));
2471
+ await this.#assertOutboxCapacity(session.userId, materializations.map((item) => item.command), undefined, currentCommands);
2472
+ options.assertCurrent?.();
2468
2473
  await this.#commitMaterializedEnqueues(materializations, generation, options);
2469
2474
  return materializations.map((item) => item.command.commandId);
2470
2475
  }
@@ -2489,7 +2494,7 @@ class OfflineSyncService {
2489
2494
  }
2490
2495
  this.noteScope({ userId: session.userId, scopeId });
2491
2496
  }
2492
- async #materializeEnqueue(userId, request, replicaTransaction, replaced) {
2497
+ async #materializeEnqueue(userId, request, replicaTransaction, replaced, createdAt) {
2493
2498
  const scope = { userId, scopeId: request.scopeId };
2494
2499
  this.noteScope(scope);
2495
2500
  const commandIdentity = offlineCommandLookupIdentity(request.identity);
@@ -2512,7 +2517,7 @@ class OfflineSyncService {
2512
2517
  state: 'pending',
2513
2518
  attempts: 0,
2514
2519
  retryAt: null,
2515
- createdAt: replaced?.createdAt ?? (await this.#nextCommandCreatedAt(userId)),
2520
+ createdAt: replaced?.createdAt ?? createdAt ?? (await this.#nextCommandCreatedAt(userId)),
2516
2521
  lastErrorCode: null,
2517
2522
  };
2518
2523
  if (replaced &&
@@ -2713,10 +2718,8 @@ class OfflineSyncService {
2713
2718
  #replicaRowKey(key) {
2714
2719
  return `${canonicalOfflinePrincipalId(key.userId)}:${key.scopeId}:${key.sourceKey}:${canonicalOfflineReplicaIdentity(key.identity)}`;
2715
2720
  }
2716
- async #assertOutboxCapacity(userId, newCommands, excludingCommandId) {
2717
- const currentCommands = this.#repository.getCommandsForUser
2718
- ? await this.#repository.getCommandsForUser(userId)
2719
- : (await Promise.all([...this.#knownScopes.values()].filter((scope) => scope.userId === userId).map((scope) => this.#repository.getCommands(scope)))).flat();
2721
+ async #assertOutboxCapacity(userId, newCommands, excludingCommandId, knownCommands) {
2722
+ const currentCommands = knownCommands ?? (await this.#commandsForUser(userId));
2720
2723
  const commands = excludingCommandId
2721
2724
  ? currentCommands.filter((candidate) => candidate.commandId !== excludingCommandId)
2722
2725
  : currentCommands;
@@ -2731,6 +2734,11 @@ class OfflineSyncService {
2731
2734
  throw new OfflineOutboxCapacityError('serialized_bytes', commands.length, currentBytes);
2732
2735
  }
2733
2736
  }
2737
+ async #commandsForUser(userId) {
2738
+ return this.#repository.getCommandsForUser
2739
+ ? this.#repository.getCommandsForUser(userId)
2740
+ : (await Promise.all([...this.#knownScopes.values()].filter((scope) => scope.userId === userId).map((scope) => this.#repository.getCommands(scope)))).flat();
2741
+ }
2734
2742
  #serializedOutboxBytes(commands) {
2735
2743
  return new TextEncoder().encode(JSON.stringify(commands)).byteLength;
2736
2744
  }
@@ -3415,9 +3423,7 @@ class OfflineSyncService {
3415
3423
  return commands;
3416
3424
  }
3417
3425
  async #nextCommandCreatedAt(userId) {
3418
- const commands = this.#repository.getCommandsForUser
3419
- ? await this.#repository.getCommandsForUser(userId)
3420
- : await this.#readKnownCommands();
3426
+ const commands = await this.#commandsForUser(userId);
3421
3427
  this.#rememberCreatedAt(commands);
3422
3428
  const createdAt = Math.max(Date.now(), this.#lastCommandCreatedAt + 1);
3423
3429
  this.#lastCommandCreatedAt = createdAt;