@rdlabo/ionic-angular-kit 21.5.13 → 21.5.15
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
|
@@ -496,9 +496,7 @@ identifier, or access token; generate a cryptographically random value for the f
|
|
|
496
496
|
|
|
497
497
|
```ts
|
|
498
498
|
import { CapacitorSQLite, SQLiteConnection } from '@capacitor-community/sqlite';
|
|
499
|
-
|
|
500
|
-
const createRandomOfflineEncryptionKey = async () =>
|
|
501
|
-
Array.from(crypto.getRandomValues(new Uint8Array(32)), (byte) => byte.toString(16).padStart(2, '0')).join('');
|
|
499
|
+
import { createRandomOfflineEncryptionKey, provideOffline } from '@rdlabo/ionic-angular-kit/offline';
|
|
502
500
|
|
|
503
501
|
provideOffline({
|
|
504
502
|
databaseName: 'product-offline',
|
|
@@ -2074,6 +2074,7 @@ class OfflineOutboxCapacityError extends Error {
|
|
|
2074
2074
|
}
|
|
2075
2075
|
const MAX_PARALLEL_AGGREGATES = 3;
|
|
2076
2076
|
const MAX_BACKOFF_MS = 60 * 60 * 1000;
|
|
2077
|
+
const POST_SEND_PULL_RETRY_MS = 1_000;
|
|
2077
2078
|
const DEFAULT_MAX_OUTBOX_COMMANDS_PER_USER = 1_000;
|
|
2078
2079
|
const DEFAULT_MAX_OUTBOX_BYTES_PER_USER = 10 * 1024 * 1024;
|
|
2079
2080
|
/** Maintains the optimistic local replica and synchronizes its durable outbox. */
|
|
@@ -2366,7 +2367,7 @@ class OfflineSyncService {
|
|
|
2366
2367
|
if (options.flush !== false && this.#network.connected())
|
|
2367
2368
|
this.#flushInBackground();
|
|
2368
2369
|
}
|
|
2369
|
-
/** Clears a retry backoff selected explicitly by the user and sends the durable command now. */
|
|
2370
|
+
/** Clears a retry backoff/auth block selected explicitly by the user and sends the durable command now. */
|
|
2370
2371
|
async retryNow(commandId) {
|
|
2371
2372
|
await this.initialize();
|
|
2372
2373
|
this.#invalidateFlush();
|
|
@@ -2379,8 +2380,8 @@ class OfflineSyncService {
|
|
|
2379
2380
|
const current = (await this.#readKnownCommands()).find((item) => item.commandId === commandId);
|
|
2380
2381
|
if (!current)
|
|
2381
2382
|
return false;
|
|
2382
|
-
if (current.state !== 'retry_wait') {
|
|
2383
|
-
throw new Error(`Offline command ${commandId} is not waiting for retry.`);
|
|
2383
|
+
if (current.state !== 'retry_wait' && current.state !== 'blocked_auth') {
|
|
2384
|
+
throw new Error(`Offline command ${commandId} is not waiting for retry or reauthentication.`);
|
|
2384
2385
|
}
|
|
2385
2386
|
await repository.putCommand({ ...current, state: 'pending', retryAt: null, lastErrorCode: null });
|
|
2386
2387
|
return true;
|
|
@@ -2427,6 +2428,7 @@ class OfflineSyncService {
|
|
|
2427
2428
|
return;
|
|
2428
2429
|
await this.#pull.pull(scope);
|
|
2429
2430
|
}
|
|
2431
|
+
const dirtyScopes = new Map();
|
|
2430
2432
|
while (this.#network.connected() && this.#isCurrent(generation)) {
|
|
2431
2433
|
const groups = this.#eligibleAggregateGroups(await this.#readKnownCommands());
|
|
2432
2434
|
if (!this.#isCurrent(generation))
|
|
@@ -2438,12 +2440,33 @@ class OfflineSyncService {
|
|
|
2438
2440
|
while (cursor < groups.length) {
|
|
2439
2441
|
const group = groups[cursor++];
|
|
2440
2442
|
if (group && this.#isCurrent(generation))
|
|
2441
|
-
await this.#sendAggregate(group, generation);
|
|
2443
|
+
await this.#sendAggregate(group, generation, dirtyScopes);
|
|
2442
2444
|
}
|
|
2443
2445
|
});
|
|
2444
2446
|
await Promise.all(workers);
|
|
2445
2447
|
}
|
|
2448
|
+
const postPullFailures = [];
|
|
2449
|
+
for (const scope of dirtyScopes.values()) {
|
|
2450
|
+
if (!this.#isCurrent(generation) || !this.#network.connected())
|
|
2451
|
+
break;
|
|
2452
|
+
try {
|
|
2453
|
+
// A command response may contain only the aggregate's base row. Pull
|
|
2454
|
+
// once per dirty scope so sibling-table journal entries are visible
|
|
2455
|
+
// before the completed Outbox state is exposed to product UI.
|
|
2456
|
+
await this.#pull.pull(scope);
|
|
2457
|
+
}
|
|
2458
|
+
catch (error) {
|
|
2459
|
+
postPullFailures.push(error);
|
|
2460
|
+
}
|
|
2461
|
+
}
|
|
2446
2462
|
await this.#refreshState(generation);
|
|
2463
|
+
if (postPullFailures.length > 0 && this.#isCurrent(generation)) {
|
|
2464
|
+
// The server command is already committed and acknowledged locally, so
|
|
2465
|
+
// never resend it. Retry only the idempotent scope pull and surface the
|
|
2466
|
+
// failure to explicit flush callers/ErrorHandler.
|
|
2467
|
+
this.#scheduleRetry(Date.now() + POST_SEND_PULL_RETRY_MS);
|
|
2468
|
+
throw postPullFailures[0];
|
|
2469
|
+
}
|
|
2447
2470
|
}
|
|
2448
2471
|
#eligibleAggregateGroups(commands) {
|
|
2449
2472
|
const now = Date.now();
|
|
@@ -2459,7 +2482,7 @@ class OfflineSyncService {
|
|
|
2459
2482
|
return head?.state === 'pending' || (head?.state === 'retry_wait' && (head.retryAt ?? 0) <= now);
|
|
2460
2483
|
});
|
|
2461
2484
|
}
|
|
2462
|
-
async #sendAggregate(commands, generation) {
|
|
2485
|
+
async #sendAggregate(commands, generation, dirtyScopes) {
|
|
2463
2486
|
for (const command of commands) {
|
|
2464
2487
|
if (!this.#isCurrent(generation))
|
|
2465
2488
|
return;
|
|
@@ -2504,6 +2527,10 @@ class OfflineSyncService {
|
|
|
2504
2527
|
if (!this.#isCurrent(generation))
|
|
2505
2528
|
return;
|
|
2506
2529
|
await this.#completeCommand(commands, sending, result, generation);
|
|
2530
|
+
if (this.#isCurrent(generation)) {
|
|
2531
|
+
const scope = { userId: sending.userId, scopeId: sending.scopeId };
|
|
2532
|
+
dirtyScopes.set(this.#scopeKey(scope), scope);
|
|
2533
|
+
}
|
|
2507
2534
|
}
|
|
2508
2535
|
}
|
|
2509
2536
|
async #normalizeEnqueueRequest(scope, request, commandIdentity) {
|
|
@@ -3132,6 +3159,16 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.17", ngImpo
|
|
|
3132
3159
|
const COMMUNITY_SQLITE = new InjectionToken('COMMUNITY_SQLITE', {
|
|
3133
3160
|
factory: () => null,
|
|
3134
3161
|
});
|
|
3162
|
+
/**
|
|
3163
|
+
* Create a cryptographically random 256-bit key for a first-install offline SQLite database.
|
|
3164
|
+
*
|
|
3165
|
+
* The returned lower-case hexadecimal value is suitable for
|
|
3166
|
+
* `OfflineKitOptions.createEncryptionKey` and contains no device or user identifiers.
|
|
3167
|
+
*/
|
|
3168
|
+
function createRandomOfflineEncryptionKey() {
|
|
3169
|
+
const bytes = crypto.getRandomValues(new Uint8Array(32));
|
|
3170
|
+
return Promise.resolve(Array.from(bytes, (byte) => byte.toString(16).padStart(2, '0')).join(''));
|
|
3171
|
+
}
|
|
3135
3172
|
/** Create the standard encrypted `@capacitor-community/sqlite` driver. */
|
|
3136
3173
|
function createCommunitySqliteDriver(connection) {
|
|
3137
3174
|
const databases = new Map();
|
|
@@ -4000,5 +4037,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.17", ngImpo
|
|
|
4000
4037
|
* Generated bundle index. Do not edit.
|
|
4001
4038
|
*/
|
|
4002
4039
|
|
|
4003
|
-
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, assertOfflineLocalId, assertOfflineReplicaGeneratedRemoteId, assertOfflineReplicaNaturalKeyBaseline, booleanColumn, canonicalOfflineCommandIdentity, canonicalOfflinePrincipalId, canonicalOfflineRemoteIdentity, canonicalOfflineReplicaIdentity, commandIdentityFromReplicaIdentity, commandIdentityMatchesReplicaRow, createCommunitySqliteDriver, createOfflineAuthBridge, datetime, decodeOfflineReplicaValues, defineOfflineReplicaSchema, defineReplicaEntity, encodeOfflineReplicaValues, generatedId, ignored, integer, isOfflineFallbackError, json, localOnly, naturalKey, normalizeOfflineNaturalKey, normalizeOfflineReplicaPullPage, nullable, offlineCommandLookupIdentity, offlineCommandTargetFromReplicaRow, offlineGeneratedReplicaIdentity, offlineInterceptor, offlineNaturalKeyFromValues, offlineNaturalReplicaIdentity, offlineReplicaRemoteIdentity, offlineSessionManifestAllows, parseOfflineCommandIdentity, parseOfflinePrincipalId, projectOfflineReplicaValues, provideOffline, provideOfflineRequestPolicy, real, replicaAddressFromIdentity, requirePositiveOfflineInteger, selectOfflineRepository, serializeOfflineCommandIdentity, sha256OfflineReplicaSchema, text };
|
|
4040
|
+
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, assertOfflineLocalId, assertOfflineReplicaGeneratedRemoteId, assertOfflineReplicaNaturalKeyBaseline, booleanColumn, canonicalOfflineCommandIdentity, canonicalOfflinePrincipalId, canonicalOfflineRemoteIdentity, canonicalOfflineReplicaIdentity, commandIdentityFromReplicaIdentity, commandIdentityMatchesReplicaRow, createCommunitySqliteDriver, createOfflineAuthBridge, createRandomOfflineEncryptionKey, datetime, decodeOfflineReplicaValues, defineOfflineReplicaSchema, defineReplicaEntity, encodeOfflineReplicaValues, generatedId, ignored, integer, isOfflineFallbackError, json, localOnly, naturalKey, normalizeOfflineNaturalKey, normalizeOfflineReplicaPullPage, nullable, offlineCommandLookupIdentity, offlineCommandTargetFromReplicaRow, offlineGeneratedReplicaIdentity, offlineInterceptor, offlineNaturalKeyFromValues, offlineNaturalReplicaIdentity, offlineReplicaRemoteIdentity, offlineSessionManifestAllows, parseOfflineCommandIdentity, parseOfflinePrincipalId, projectOfflineReplicaValues, provideOffline, provideOfflineRequestPolicy, real, replicaAddressFromIdentity, requirePositiveOfflineInteger, selectOfflineRepository, serializeOfflineCommandIdentity, sha256OfflineReplicaSchema, text };
|
|
4004
4041
|
//# sourceMappingURL=rdlabo-ionic-angular-kit-offline.mjs.map
|