@rdlabo/ionic-angular-kit 21.5.39 → 21.5.40
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
|
@@ -578,8 +578,10 @@ baseline. The server remains authoritative; SQLite is the durable local working
|
|
|
578
578
|
Synchronized mode requires `aggregateIntentProjector`. Kit calls it inside `OfflineReplicaMutationCoordinator` after
|
|
579
579
|
enqueue, batch enqueue, replacement, discard, transport success, and pull acknowledgement. The adapter must derive
|
|
580
580
|
only from authoritative confirmed values plus the complete remaining intent chain. Do not call it from product code.
|
|
581
|
-
Commands persist payload
|
|
582
|
-
|
|
581
|
+
Commands persist an immutable payload plus Kit-owned metadata (`baseRevision`, state, footprint keys). Kit updates
|
|
582
|
+
only `baseRevision` when a newer server revision is known, and sets it to `null` after a generated remote identity is
|
|
583
|
+
released; the product executor always receives the original payload. Optimistic snapshots and companion before/after
|
|
584
|
+
images are not durable truth.
|
|
583
585
|
|
|
584
586
|
When an API response is assembled from a base replica row plus product-owned local-only view rows, use
|
|
585
587
|
`enqueuePrepared()`. Its callback runs inside the shared replica mutation lane, so every read used to derive the
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { InjectionToken, inject, Injectable, signal, computed, ErrorHandler, effect, makeEnvironmentProviders, provideAppInitializer } from '@angular/core';
|
|
2
|
+
import { InjectionToken, inject, Injectable, signal, computed, ErrorHandler, effect, untracked, makeEnvironmentProviders, provideAppInitializer } from '@angular/core';
|
|
3
3
|
import { KitStorageService } from '@rdlabo/ionic-angular-kit';
|
|
4
4
|
import { toObservable } from '@angular/core/rxjs-interop';
|
|
5
5
|
import { map, distinctUntilChanged } from 'rxjs/operators';
|
|
@@ -897,6 +897,16 @@ const OFFLINE_COMMAND_HOOKS = new InjectionToken('OFFLINE_COMMAND_HOOKS', {
|
|
|
897
897
|
/** DI token for product-independent offline persistence settings. */
|
|
898
898
|
const OFFLINE_KIT_OPTIONS = new InjectionToken('OFFLINE_KIT_OPTIONS');
|
|
899
899
|
|
|
900
|
+
/**
|
|
901
|
+
* Returns a command whose only changed field is `baseRevision`.
|
|
902
|
+
*
|
|
903
|
+
* Payload and every other field are copied unchanged. Kit uses this when a
|
|
904
|
+
* newer server revision is known, and passes `null` after a generated remote
|
|
905
|
+
* identity is released.
|
|
906
|
+
*/
|
|
907
|
+
function offlineCommandWithBaseRevision(command, baseRevision) {
|
|
908
|
+
return { ...command, baseRevision };
|
|
909
|
+
}
|
|
900
910
|
/** DI token for the product-specific command transport adapter. */
|
|
901
911
|
const OFFLINE_COMMAND_EXECUTOR = new InjectionToken('OFFLINE_COMMAND_EXECUTOR');
|
|
902
912
|
/** DI token for authenticated synchronization context. */
|
|
@@ -1973,7 +1983,6 @@ class OfflineReplicaPullService {
|
|
|
1973
1983
|
#options = inject(OFFLINE_KIT_OPTIONS);
|
|
1974
1984
|
#puller = inject(OFFLINE_REPLICA_PULLER);
|
|
1975
1985
|
#projector = inject(OFFLINE_REPLICA_PROJECTOR, { optional: true });
|
|
1976
|
-
#executor = inject(OFFLINE_COMMAND_EXECUTOR);
|
|
1977
1986
|
#hooks = inject(OFFLINE_COMMAND_HOOKS);
|
|
1978
1987
|
#replicaMutations = inject(OfflineReplicaMutationCoordinator);
|
|
1979
1988
|
#schemaHash = null;
|
|
@@ -2024,8 +2033,6 @@ class OfflineReplicaPullService {
|
|
|
2024
2033
|
const projection = await this.#projector?.project({
|
|
2025
2034
|
scope,
|
|
2026
2035
|
changes,
|
|
2027
|
-
commands: scopeCommands,
|
|
2028
|
-
repository: this.#repository,
|
|
2029
2036
|
});
|
|
2030
2037
|
this.#assertProjection(scope, projection);
|
|
2031
2038
|
const putRows = [];
|
|
@@ -2112,6 +2119,7 @@ class OfflineReplicaPullService {
|
|
|
2112
2119
|
for (const command of related) {
|
|
2113
2120
|
putCommands.set(command.commandId, { ...command, state: 'conflict', retryAt: null, lastErrorCode: 'remote_deleted' });
|
|
2114
2121
|
}
|
|
2122
|
+
rematerializeAfter.push(related[0]);
|
|
2115
2123
|
continue;
|
|
2116
2124
|
}
|
|
2117
2125
|
const confirmedValues = this.#validatedValues(schema, change);
|
|
@@ -2143,7 +2151,7 @@ class OfflineReplicaPullService {
|
|
|
2143
2151
|
if (remaining.length > 0)
|
|
2144
2152
|
rematerializeAfter.push(remaining[0]);
|
|
2145
2153
|
for (const command of remaining) {
|
|
2146
|
-
putCommands.set(command.commandId,
|
|
2154
|
+
putCommands.set(command.commandId, offlineCommandWithBaseRevision(command, change.serverRevision));
|
|
2147
2155
|
}
|
|
2148
2156
|
}
|
|
2149
2157
|
const confirmedAndProjected = this.#mergeRowMutations([
|
|
@@ -2480,9 +2488,9 @@ class OfflineReplicaPullService {
|
|
|
2480
2488
|
const acknowledgementSuperseded = (change.acknowledgementOrdinals[lastAcknowledgedCommand.commandId] ?? -1) < change.collapsedOrdinal;
|
|
2481
2489
|
const following = related
|
|
2482
2490
|
.slice(lastAcknowledgedIndex + 1)
|
|
2483
|
-
.map((command) => acknowledgementSuperseded
|
|
2491
|
+
.map((command) => acknowledgementSuperseded || change.deleted
|
|
2484
2492
|
? { ...command, state: 'conflict', retryAt: null, lastErrorCode: change.deleted ? 'remote_deleted' : 'remote_revision' }
|
|
2485
|
-
:
|
|
2493
|
+
: offlineCommandWithBaseRevision(command, change.serverRevision));
|
|
2486
2494
|
for (const command of following)
|
|
2487
2495
|
putCommands.set(command.commandId, command);
|
|
2488
2496
|
for (const command of related.slice(0, lastAcknowledgedIndex + 1)) {
|
|
@@ -2495,15 +2503,10 @@ class OfflineReplicaPullService {
|
|
|
2495
2503
|
...row,
|
|
2496
2504
|
confirmedValues: null,
|
|
2497
2505
|
serverRevision: change.serverRevision,
|
|
2498
|
-
syncState:
|
|
2506
|
+
syncState: 'conflict',
|
|
2499
2507
|
visibility: following.at(-1).replicaMutation === 'delete' ? 'pending_delete' : 'present',
|
|
2500
2508
|
fetchedAt: Date.now(),
|
|
2501
2509
|
});
|
|
2502
|
-
if (acknowledgementSuperseded) {
|
|
2503
|
-
for (const command of following) {
|
|
2504
|
-
putCommands.set(command.commandId, { ...command, state: 'conflict', lastErrorCode: 'remote_deleted' });
|
|
2505
|
-
}
|
|
2506
|
-
}
|
|
2507
2510
|
}
|
|
2508
2511
|
else {
|
|
2509
2512
|
removeRows.push({ ...row, identity: row.identity });
|
|
@@ -2920,7 +2923,11 @@ class OfflineSyncService {
|
|
|
2920
2923
|
}, ...(ngDevMode ? [{ debugName: "syncState" }] : /* istanbul ignore next */ []));
|
|
2921
2924
|
effect(() => {
|
|
2922
2925
|
const connected = this.#network.connected();
|
|
2923
|
-
|
|
2926
|
+
// The network transition may be observed after an explicit flush has already
|
|
2927
|
+
// persisted a fatal pull attention. Do not let that stale transition restart
|
|
2928
|
+
// the intentionally stopped loop; auth/session refresh remains able to retry.
|
|
2929
|
+
const hasFatalPullAttention = untracked(() => this.#pullAttentions().length > 0);
|
|
2930
|
+
if (this.#initialized && connected && !hasFatalPullAttention)
|
|
2924
2931
|
this.#flushInBackground();
|
|
2925
2932
|
});
|
|
2926
2933
|
}
|
|
@@ -3182,7 +3189,6 @@ class OfflineSyncService {
|
|
|
3182
3189
|
operation: request.operation,
|
|
3183
3190
|
payload: normalized.payload,
|
|
3184
3191
|
replicaMutation: request.replicaMutation ?? 'upsert',
|
|
3185
|
-
payloadHash: await this.#payloadHash(normalized.payload),
|
|
3186
3192
|
baseRevision: normalized.baseRevision,
|
|
3187
3193
|
state: 'pending',
|
|
3188
3194
|
attempts: 0,
|
|
@@ -3795,31 +3801,12 @@ class OfflineSyncService {
|
|
|
3795
3801
|
}
|
|
3796
3802
|
async #normalizeEnqueueRequest(scope, request, commandIdentity) {
|
|
3797
3803
|
let baseRevision = request.baseRevision ?? null;
|
|
3798
|
-
let payload = request.payload;
|
|
3799
3804
|
const sourceKey = this.#hooks.entityType(request);
|
|
3800
3805
|
const row = await this.#getReplicaRowForSync(scope, sourceKey, commandIdentity);
|
|
3801
3806
|
if (row?.serverRevision != null && row.serverRevision !== baseRevision) {
|
|
3802
|
-
const rebased = this.#executor.withServerRevision({
|
|
3803
|
-
...scope,
|
|
3804
|
-
commandId: '',
|
|
3805
|
-
aggregateType: request.aggregateType,
|
|
3806
|
-
sourceKey,
|
|
3807
|
-
identity: commandIdentity,
|
|
3808
|
-
operation: request.operation,
|
|
3809
|
-
payload,
|
|
3810
|
-
replicaMutation: request.replicaMutation ?? 'upsert',
|
|
3811
|
-
payloadHash: '',
|
|
3812
|
-
baseRevision,
|
|
3813
|
-
state: 'pending',
|
|
3814
|
-
attempts: 0,
|
|
3815
|
-
retryAt: null,
|
|
3816
|
-
createdAt: 0,
|
|
3817
|
-
lastErrorCode: null,
|
|
3818
|
-
}, row.serverRevision);
|
|
3819
3807
|
baseRevision = row.serverRevision;
|
|
3820
|
-
payload = rebased.payload;
|
|
3821
3808
|
}
|
|
3822
|
-
return { payload, baseRevision };
|
|
3809
|
+
return { payload: request.payload, baseRevision };
|
|
3823
3810
|
}
|
|
3824
3811
|
async #completeCommand(commands, command, result, generation) {
|
|
3825
3812
|
return this.#serializeReplicaMutation(() => this.#completeCommandLocked(commands, command, result, generation));
|
|
@@ -3838,15 +3825,10 @@ class OfflineSyncService {
|
|
|
3838
3825
|
const revision = result.serverRevision;
|
|
3839
3826
|
const following = latestCommands.slice(latestIndex + 1);
|
|
3840
3827
|
const rebased = result.clearRemoteId === true
|
|
3841
|
-
? following.map((item) =>
|
|
3842
|
-
if (!this.#executor.withoutServerRevision) {
|
|
3843
|
-
throw new Error('Offline command executor must implement withoutServerRevision to recreate a deleted remoteId row.');
|
|
3844
|
-
}
|
|
3845
|
-
return this.#executor.withoutServerRevision(item);
|
|
3846
|
-
})
|
|
3828
|
+
? following.map((item) => offlineCommandWithBaseRevision(item, null))
|
|
3847
3829
|
: revision === undefined
|
|
3848
3830
|
? following
|
|
3849
|
-
: following.map((item) =>
|
|
3831
|
+
: following.map((item) => offlineCommandWithBaseRevision(item, revision));
|
|
3850
3832
|
const current = await this.#rowForCommand(command);
|
|
3851
3833
|
if (!this.#isCurrent(generation))
|
|
3852
3834
|
return;
|
|
@@ -4310,10 +4292,6 @@ class OfflineSyncService {
|
|
|
4310
4292
|
async #waitForSendingTransitions() {
|
|
4311
4293
|
await Promise.allSettled([...this.#sendingTransitions]);
|
|
4312
4294
|
}
|
|
4313
|
-
async #payloadHash(payload) {
|
|
4314
|
-
const digest = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(this.#canonicalJson(payload)));
|
|
4315
|
-
return [...new Uint8Array(digest)].map((byte) => byte.toString(16).padStart(2, '0')).join('');
|
|
4316
|
-
}
|
|
4317
4295
|
#canonicalJson(value) {
|
|
4318
4296
|
if (Array.isArray(value))
|
|
4319
4297
|
return `[${value.map((item) => this.#canonicalJson(item)).join(',')}]`;
|
|
@@ -5383,7 +5361,6 @@ class SqliteOfflineRepository {
|
|
|
5383
5361
|
? {}
|
|
5384
5362
|
: { localOnlyFootprint: this.#parse(row['local_only_footprint_json']) }),
|
|
5385
5363
|
replicaMutation: this.#string(row['replica_mutation']),
|
|
5386
|
-
payloadHash: this.#string(row['payload_hash']),
|
|
5387
5364
|
baseRevision: this.#parseNullable(row['base_revision_json']),
|
|
5388
5365
|
state: this.#string(row['state']),
|
|
5389
5366
|
attempts: this.#number(row['attempts']),
|
|
@@ -5423,7 +5400,7 @@ class SqliteOfflineRepository {
|
|
|
5423
5400
|
JSON.stringify(command.payload),
|
|
5424
5401
|
command.localOnlyFootprint === undefined ? null : JSON.stringify(command.localOnlyFootprint),
|
|
5425
5402
|
command.replicaMutation ?? 'upsert',
|
|
5426
|
-
|
|
5403
|
+
'',
|
|
5427
5404
|
this.#stringifyNullable(command.baseRevision),
|
|
5428
5405
|
command.state,
|
|
5429
5406
|
command.attempts,
|
|
@@ -5748,7 +5725,6 @@ const READ_CACHE_ONLY_COMMAND_EXECUTOR = {
|
|
|
5748
5725
|
execute: async () => {
|
|
5749
5726
|
throw new Error('This offline provider is configured as a read-only cache.');
|
|
5750
5727
|
},
|
|
5751
|
-
withServerRevision: (command) => command,
|
|
5752
5728
|
};
|
|
5753
5729
|
const READ_CACHE_ONLY_REPLICA_PULLER = {
|
|
5754
5730
|
pull: async (request) => ({
|
|
@@ -5944,5 +5920,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.17", ngImpo
|
|
|
5944
5920
|
* Generated bundle index. Do not edit.
|
|
5945
5921
|
*/
|
|
5946
5922
|
|
|
5947
|
-
export { COMMUNITY_SQLITE, DEFAULT_OFFLINE_COMMAND_HOOKS, IonicOfflineRepository, OFFLINE_AGGREGATE_INTENT_PROJECTOR, OFFLINE_BYPASS, OFFLINE_COMMAND_EXECUTOR, OFFLINE_COMMAND_HOOKS, OFFLINE_KIT_OPTIONS, OFFLINE_MUTATION_REQUEST_POLICIES, OFFLINE_REPLICA_PROJECTOR, OFFLINE_REPLICA_PULLER, OFFLINE_REPOSITORY, OFFLINE_REQUEST_POLICIES, OFFLINE_RESPONSE_HEADER, OFFLINE_RETRY_RANDOM, OFFLINE_SCHEMA_VERSION, OFFLINE_SYNC_CONTEXT, OfflineCommandInFlightError, OfflineCoordinatorService, OfflineMutationPolicyConflictError, OfflineMutationProtocolError, OfflineMutationRequestPolicyRegistry, OfflineNetworkService, OfflineOutboxCapacityError, OfflinePayloadValidationError, OfflineReplicaMutationCoordinator, OfflineReplicaPullService, OfflineReplicaSchemaMismatchError, OfflineRequestFallbackService, OfflineRequestPolicyRegistry, OfflineSessionService, OfflineStorageUnavailableError, OfflineSyncService, SqliteOfflineRepository, assertOfflineLocalId, assertOfflineReplicaGeneratedRemoteId, assertOfflineReplicaNaturalKeyBaseline, assertSupportedOfflineMode, booleanColumn, canonicalOfflineCommandIdentity, canonicalOfflinePrincipalId, canonicalOfflineRemoteIdentity, canonicalOfflineReplicaIdentity, canonicalOfflineReplicaRowKey, commandFootprintKeys, commandIdentityFromReplicaIdentity, commandIdentityMatchesReplicaRow, createCommunitySqliteDriver, createOfflineAuthBridge, createRandomOfflineEncryptionKey, datetime, decodeOfflineReplicaValues, defineOfflineReplicaSchema, defineReplicaEntity, encodeOfflineReplicaValues, generatedId, ignored, integer, isOfflineAggregateIntentConflict, isOfflineFallbackError, isOfflineStorageUnavailableError, json, localOnly, naturalKey, normalizeOfflineNaturalKey, normalizeOfflineReplicaPullPage, nullable, offlineAggregateIntentMutations, offlineCommandLookupIdentity, offlineCommandTargetFromReplicaRow, offlineGeneratedReplicaIdentity, offlineInterceptor, offlineNaturalKeyFromValues, offlineNaturalReplicaIdentity, offlineReplicaRemoteIdentity, offlineRetryDelayMs, offlineSessionManifestAllows, parseOfflineCommandIdentity, parseOfflineMutationEnvelope, parseOfflinePrincipalId, projectOfflineReplicaValues, provideOffline, provideOfflineMutationRequestPolicy, provideOfflineRequestPolicy, real, replicaAddressFromIdentity, requirePositiveOfflineInteger, selectOfflineRepository, serializeOfflineCommandIdentity, sha256OfflineReplicaSchema, supportsSynchronizedOfflineRepository, text };
|
|
5923
|
+
export { COMMUNITY_SQLITE, DEFAULT_OFFLINE_COMMAND_HOOKS, IonicOfflineRepository, OFFLINE_AGGREGATE_INTENT_PROJECTOR, OFFLINE_BYPASS, OFFLINE_COMMAND_EXECUTOR, OFFLINE_COMMAND_HOOKS, OFFLINE_KIT_OPTIONS, OFFLINE_MUTATION_REQUEST_POLICIES, OFFLINE_REPLICA_PROJECTOR, OFFLINE_REPLICA_PULLER, OFFLINE_REPOSITORY, OFFLINE_REQUEST_POLICIES, OFFLINE_RESPONSE_HEADER, OFFLINE_RETRY_RANDOM, OFFLINE_SCHEMA_VERSION, OFFLINE_SYNC_CONTEXT, OfflineCommandInFlightError, OfflineCoordinatorService, OfflineMutationPolicyConflictError, OfflineMutationProtocolError, OfflineMutationRequestPolicyRegistry, OfflineNetworkService, OfflineOutboxCapacityError, OfflinePayloadValidationError, OfflineReplicaMutationCoordinator, OfflineReplicaPullService, OfflineReplicaSchemaMismatchError, OfflineRequestFallbackService, OfflineRequestPolicyRegistry, OfflineSessionService, OfflineStorageUnavailableError, OfflineSyncService, SqliteOfflineRepository, assertOfflineLocalId, assertOfflineReplicaGeneratedRemoteId, assertOfflineReplicaNaturalKeyBaseline, assertSupportedOfflineMode, booleanColumn, canonicalOfflineCommandIdentity, canonicalOfflinePrincipalId, canonicalOfflineRemoteIdentity, canonicalOfflineReplicaIdentity, canonicalOfflineReplicaRowKey, commandFootprintKeys, commandIdentityFromReplicaIdentity, commandIdentityMatchesReplicaRow, createCommunitySqliteDriver, createOfflineAuthBridge, createRandomOfflineEncryptionKey, datetime, decodeOfflineReplicaValues, defineOfflineReplicaSchema, defineReplicaEntity, encodeOfflineReplicaValues, generatedId, ignored, integer, isOfflineAggregateIntentConflict, isOfflineFallbackError, isOfflineStorageUnavailableError, json, localOnly, naturalKey, normalizeOfflineNaturalKey, normalizeOfflineReplicaPullPage, nullable, offlineAggregateIntentMutations, offlineCommandLookupIdentity, offlineCommandTargetFromReplicaRow, offlineCommandWithBaseRevision, offlineGeneratedReplicaIdentity, offlineInterceptor, offlineNaturalKeyFromValues, offlineNaturalReplicaIdentity, offlineReplicaRemoteIdentity, offlineRetryDelayMs, offlineSessionManifestAllows, parseOfflineCommandIdentity, parseOfflineMutationEnvelope, parseOfflinePrincipalId, projectOfflineReplicaValues, provideOffline, provideOfflineMutationRequestPolicy, provideOfflineRequestPolicy, real, replicaAddressFromIdentity, requirePositiveOfflineInteger, selectOfflineRepository, serializeOfflineCommandIdentity, sha256OfflineReplicaSchema, supportsSynchronizedOfflineRepository, text };
|
|
5948
5924
|
//# sourceMappingURL=rdlabo-ionic-angular-kit-offline.mjs.map
|