@rdlabo/ionic-angular-kit 21.5.4 → 21.5.5
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.
package/README.md
CHANGED
|
@@ -520,6 +520,13 @@ The write lifecycle is: update the replica immediately → append an outbox comm
|
|
|
520
520
|
the optimistic value → replay in the background → validate the server revision → store the confirmed value and
|
|
521
521
|
revision. The server remains authoritative; SQLite is the durable local working database, not an HTTP response cache.
|
|
522
522
|
|
|
523
|
+
The runtime retains pending, rejected, and conflicted commands until synchronization or an explicit user discard;
|
|
524
|
+
it never evicts an unconfirmed mutation because of age or storage pressure. To keep a device that remains offline for
|
|
525
|
+
months from exhausting SQLite, enqueue applies backpressure at 1,000 commands or 10 MiB per user by default. Products
|
|
526
|
+
may lower these limits with `outboxLimits: { maxCommandsPerUser, maxBytesPerUser }`. When a limit is reached, the
|
|
527
|
+
existing replica and Outbox remain unchanged and enqueue rejects with `OfflineOutboxCapacityError`, so the UI can ask
|
|
528
|
+
the user to reconnect or resolve/discard an attention item.
|
|
529
|
+
|
|
523
530
|
`serverId()` supports positive safe integers only. Products must expose an internal numeric primary key for a
|
|
524
531
|
replicated entity; a human-facing string such as a public code, slip number, or SKU remains an ordinary replicated
|
|
525
532
|
column. There is intentionally no text-server-id overload.
|
|
@@ -1472,8 +1472,22 @@ class OfflinePayloadValidationError extends Error {
|
|
|
1472
1472
|
this.name = 'OfflinePayloadValidationError';
|
|
1473
1473
|
}
|
|
1474
1474
|
}
|
|
1475
|
+
/** Raised before persistence when retaining another command would exceed the configured durable Outbox capacity. */
|
|
1476
|
+
class OfflineOutboxCapacityError extends Error {
|
|
1477
|
+
constructor(reason, currentCommands, currentBytes) {
|
|
1478
|
+
super(reason === 'command_count'
|
|
1479
|
+
? 'Offline Outbox command limit reached; synchronize or discard a pending command before continuing'
|
|
1480
|
+
: 'Offline Outbox storage limit reached; synchronize or discard a pending command before continuing');
|
|
1481
|
+
this.reason = reason;
|
|
1482
|
+
this.currentCommands = currentCommands;
|
|
1483
|
+
this.currentBytes = currentBytes;
|
|
1484
|
+
this.name = 'OfflineOutboxCapacityError';
|
|
1485
|
+
}
|
|
1486
|
+
}
|
|
1475
1487
|
const MAX_PARALLEL_AGGREGATES = 3;
|
|
1476
1488
|
const MAX_BACKOFF_MS = 60 * 60 * 1000;
|
|
1489
|
+
const DEFAULT_MAX_OUTBOX_COMMANDS_PER_USER = 1_000;
|
|
1490
|
+
const DEFAULT_MAX_OUTBOX_BYTES_PER_USER = 10 * 1024 * 1024;
|
|
1477
1491
|
/** Maintains the optimistic local replica and synchronizes its durable outbox. */
|
|
1478
1492
|
class OfflineSyncService {
|
|
1479
1493
|
#network;
|
|
@@ -1617,6 +1631,7 @@ class OfflineSyncService {
|
|
|
1617
1631
|
createdAt: await this.#nextCommandCreatedAt(userId),
|
|
1618
1632
|
lastErrorCode: null,
|
|
1619
1633
|
};
|
|
1634
|
+
await this.#assertOutboxCapacity(userId, command);
|
|
1620
1635
|
const entityType = this.#entityType(command);
|
|
1621
1636
|
const existing = await this.#repository.getReplicaRow(scope, entityType, aggregateLocalId);
|
|
1622
1637
|
const initialServerId = this.#initialServerId(existing?.serverId ?? null, request.serverId);
|
|
@@ -1646,6 +1661,24 @@ class OfflineSyncService {
|
|
|
1646
1661
|
this.#flushInBackground();
|
|
1647
1662
|
return commandId;
|
|
1648
1663
|
}
|
|
1664
|
+
async #assertOutboxCapacity(userId, command) {
|
|
1665
|
+
const commands = this.#repository.getCommandsForUser
|
|
1666
|
+
? await this.#repository.getCommandsForUser(userId)
|
|
1667
|
+
: (await Promise.all([...this.#knownScopes.values()].filter((scope) => scope.userId === userId).map((scope) => this.#repository.getCommands(scope)))).flat();
|
|
1668
|
+
const maxCommands = this.#options.outboxLimits?.maxCommandsPerUser ?? DEFAULT_MAX_OUTBOX_COMMANDS_PER_USER;
|
|
1669
|
+
const maxBytes = this.#options.outboxLimits?.maxBytesPerUser ?? DEFAULT_MAX_OUTBOX_BYTES_PER_USER;
|
|
1670
|
+
const currentBytes = this.#serializedOutboxBytes(commands);
|
|
1671
|
+
if (commands.length >= maxCommands) {
|
|
1672
|
+
throw new OfflineOutboxCapacityError('command_count', commands.length, currentBytes);
|
|
1673
|
+
}
|
|
1674
|
+
const nextBytes = currentBytes + this.#serializedOutboxBytes([command]);
|
|
1675
|
+
if (nextBytes > maxBytes) {
|
|
1676
|
+
throw new OfflineOutboxCapacityError('serialized_bytes', commands.length, currentBytes);
|
|
1677
|
+
}
|
|
1678
|
+
}
|
|
1679
|
+
#serializedOutboxBytes(commands) {
|
|
1680
|
+
return new TextEncoder().encode(JSON.stringify(commands)).byteLength;
|
|
1681
|
+
}
|
|
1649
1682
|
async discard(commandId, options = {}) {
|
|
1650
1683
|
await this.initialize();
|
|
1651
1684
|
const command = (await this.#readKnownCommands()).find((item) => item.commandId === commandId);
|
|
@@ -2829,6 +2862,7 @@ function provideOffline(options) {
|
|
|
2829
2862
|
databaseName: options.databaseName,
|
|
2830
2863
|
createEncryptionKey: options.createEncryptionKey,
|
|
2831
2864
|
replicaSchema: options.replicaSchema,
|
|
2865
|
+
outboxLimits: options.outboxLimits,
|
|
2832
2866
|
},
|
|
2833
2867
|
},
|
|
2834
2868
|
{
|
|
@@ -2910,5 +2944,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.17", ngImpo
|
|
|
2910
2944
|
* Generated bundle index. Do not edit.
|
|
2911
2945
|
*/
|
|
2912
2946
|
|
|
2913
|
-
export { COMMUNITY_SQLITE, DEFAULT_OFFLINE_COMMAND_HOOKS, IonicOfflineRepository, OFFLINE_BYPASS, OFFLINE_COMMAND_EXECUTOR, OFFLINE_COMMAND_HOOKS, OFFLINE_KIT_OPTIONS, OFFLINE_REPLICA_PULLER, OFFLINE_REPOSITORY, OFFLINE_REQUEST_POLICIES, OFFLINE_RESPONSE_HEADER, OFFLINE_SCHEMA_VERSION, OFFLINE_SYNC_CONTEXT, OfflineCoordinatorService, OfflineNetworkService, OfflinePayloadValidationError, OfflineReplicaPullService, OfflineRequestFallbackService, OfflineRequestPolicyRegistry, OfflineSessionService, OfflineSyncService, SqliteOfflineRepository, assertOfflineReplicaServerId, booleanColumn, createCommunitySqliteDriver, createOfflineAuthBridge, datetime, decodeOfflineReplicaValues, defineOfflineReplicaSchema, defineReplicaEntity, encodeOfflineReplicaValues, ignored, integer, isOfflineFallbackError, json, nullable, offlineInterceptor, projectOfflineReplicaValues, provideOffline, provideOfflineRequestPolicy, real, selectOfflineRepository, serverId, sha256OfflineReplicaSchema, text };
|
|
2947
|
+
export { COMMUNITY_SQLITE, DEFAULT_OFFLINE_COMMAND_HOOKS, IonicOfflineRepository, OFFLINE_BYPASS, OFFLINE_COMMAND_EXECUTOR, OFFLINE_COMMAND_HOOKS, OFFLINE_KIT_OPTIONS, OFFLINE_REPLICA_PULLER, OFFLINE_REPOSITORY, OFFLINE_REQUEST_POLICIES, OFFLINE_RESPONSE_HEADER, OFFLINE_SCHEMA_VERSION, OFFLINE_SYNC_CONTEXT, OfflineCoordinatorService, OfflineNetworkService, OfflineOutboxCapacityError, OfflinePayloadValidationError, OfflineReplicaPullService, OfflineRequestFallbackService, OfflineRequestPolicyRegistry, OfflineSessionService, OfflineSyncService, SqliteOfflineRepository, assertOfflineReplicaServerId, booleanColumn, createCommunitySqliteDriver, createOfflineAuthBridge, datetime, decodeOfflineReplicaValues, defineOfflineReplicaSchema, defineReplicaEntity, encodeOfflineReplicaValues, ignored, integer, isOfflineFallbackError, json, nullable, offlineInterceptor, projectOfflineReplicaValues, provideOffline, provideOfflineRequestPolicy, real, selectOfflineRepository, serverId, sha256OfflineReplicaSchema, text };
|
|
2914
2948
|
//# sourceMappingURL=rdlabo-ionic-angular-kit-offline.mjs.map
|