@rdlabo/ionic-angular-kit 21.5.10 → 21.5.12
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
|
@@ -391,8 +391,10 @@ A fleet-canonical HTTP interceptor with:
|
|
|
391
391
|
|
|
392
392
|
The optional `offline` entry point provides a user/partition-scoped local replica, durable outbox, authenticated
|
|
393
393
|
session boundary, cursor-based delta pull, aggregate-ordered replay, optimistic updates, retry classification, and a
|
|
394
|
-
read-only request-policy interceptor.
|
|
395
|
-
executor through `provideOffline(...)`.
|
|
394
|
+
read-only request-policy interceptor. Synchronized applications provide URL/DTO read policies, a replica puller, and
|
|
395
|
+
a command executor through `provideOffline(...)`. External-source or HTTP read caches use
|
|
396
|
+
`mode: 'readCacheOnly'`; the kit then supplies the empty pull/executor boundary instead of making every product
|
|
397
|
+
declare dummy adapters.
|
|
396
398
|
Mutations are queued explicitly with `OfflineSyncService.enqueue`, not through HTTP interceptor policy.
|
|
397
399
|
Web storage uses Ionic Storage; iOS and Android use encrypted `@capacitor-community/sqlite`. Importing either the
|
|
398
400
|
primary entry point or `/offline` does not pull the optional native SQLite plugin into web-only applications.
|
|
@@ -602,6 +604,10 @@ to `conflict`; the new server value is retained as the confirmed baseline. A rem
|
|
|
602
604
|
retention rule: without pending commands it removes the row, while a pending row and its Outbox remain under
|
|
603
605
|
`remote_deleted` conflict so the user can resolve or discard them.
|
|
604
606
|
|
|
607
|
+
Hono payloads may call a generated database key `serverId`, while the database-independent runtime calls it
|
|
608
|
+
`remoteId`. Product pullers must use `normalizeOfflineReplicaPullPage(response)` at the HTTP boundary; do not
|
|
609
|
+
reimplement `serverId` stripping/injection per application. Natural-key changes pass through unchanged.
|
|
610
|
+
|
|
605
611
|
The command adapter must send `commandId` as the server-side idempotency key. The server persists that key with the
|
|
606
612
|
mutation and returns all keys represented by a delta row as `acknowledgedCommandIds`. This correlation is required:
|
|
607
613
|
if the server commits a create/update/delete but its HTTP acknowledgement is lost, the next pull reconciles the
|
|
@@ -690,6 +696,15 @@ provideOffline({
|
|
|
690
696
|
commandExecutor: ProductCommandExecutor,
|
|
691
697
|
// ...request policies, databaseName, createEncryptionKey
|
|
692
698
|
});
|
|
699
|
+
|
|
700
|
+
// Stripe or another external system is the source of truth; no Outbox exists.
|
|
701
|
+
provideOffline({
|
|
702
|
+
mode: 'readCacheOnly',
|
|
703
|
+
replicaSchema: readCacheSchema,
|
|
704
|
+
requestPolicies: [ReadCacheRequestPolicy],
|
|
705
|
+
databaseName: 'product-read-cache',
|
|
706
|
+
createEncryptionKey,
|
|
707
|
+
});
|
|
693
708
|
```
|
|
694
709
|
|
|
695
710
|
Offline replica schema consumers must compile with TypeScript `strictNullChecks: true`. This is part of the standard,
|
|
@@ -680,6 +680,13 @@ function assertPositiveInteger(value, label) {
|
|
|
680
680
|
}
|
|
681
681
|
}
|
|
682
682
|
|
|
683
|
+
/** Narrows a product DB id without duplicating the numeric identity boundary. */
|
|
684
|
+
function requirePositiveOfflineInteger(value, label = 'Offline id') {
|
|
685
|
+
if (typeof value !== 'number' || !Number.isSafeInteger(value) || value <= 0) {
|
|
686
|
+
throw new Error(`${label} must be a positive safe integer.`);
|
|
687
|
+
}
|
|
688
|
+
return value;
|
|
689
|
+
}
|
|
683
690
|
/** Type-tagged SQLite/web key; numeric 7 and text "7" never share a boundary. */
|
|
684
691
|
function canonicalOfflinePrincipalId(value) {
|
|
685
692
|
if (typeof value === 'number') {
|
|
@@ -817,6 +824,27 @@ function isPlainObject$1(value) {
|
|
|
817
824
|
return prototype === Object.prototype || prototype === null;
|
|
818
825
|
}
|
|
819
826
|
|
|
827
|
+
/**
|
|
828
|
+
* Converts a backend DB identity (`serverId`) to the runtime identity
|
|
829
|
+
* (`remoteId`) without allowing product pullers to each reimplement the rule.
|
|
830
|
+
*/
|
|
831
|
+
function normalizeOfflineReplicaPullPage(page) {
|
|
832
|
+
return {
|
|
833
|
+
...page,
|
|
834
|
+
changes: page.changes.map((change, index) => {
|
|
835
|
+
if ('naturalKey' in change)
|
|
836
|
+
return change;
|
|
837
|
+
if ('serverId' in change && 'remoteId' in change) {
|
|
838
|
+
throw new Error(`Offline replica pull page changes[${index}] cannot contain both serverId and remoteId.`);
|
|
839
|
+
}
|
|
840
|
+
if ('serverId' in change) {
|
|
841
|
+
const { serverId, ...rest } = change;
|
|
842
|
+
return { ...rest, remoteId: serverId };
|
|
843
|
+
}
|
|
844
|
+
return change;
|
|
845
|
+
}),
|
|
846
|
+
};
|
|
847
|
+
}
|
|
820
848
|
/** DI token for the application-provided explicit replica pull transport. */
|
|
821
849
|
const OFFLINE_REPLICA_PULLER = new InjectionToken('OFFLINE_REPLICA_PULLER');
|
|
822
850
|
|
|
@@ -1462,6 +1490,8 @@ class OfflineReplicaPullService {
|
|
|
1462
1490
|
#executor = inject(OFFLINE_COMMAND_EXECUTOR);
|
|
1463
1491
|
#schemaHash = null;
|
|
1464
1492
|
async pull(scope) {
|
|
1493
|
+
if (this.#options.mode === 'readCacheOnly')
|
|
1494
|
+
return;
|
|
1465
1495
|
const schemaHash = await (this.#schemaHash ??= sha256OfflineReplicaSchema(this.#options.replicaSchema));
|
|
1466
1496
|
let cursor = (await this.#repository.getReplicaCursor(scope))?.cursor ?? '';
|
|
1467
1497
|
for (;;) {
|
|
@@ -1869,6 +1899,12 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.17", ngImpo
|
|
|
1869
1899
|
args: [{ providedIn: 'root' }]
|
|
1870
1900
|
}] });
|
|
1871
1901
|
|
|
1902
|
+
/** Checks the authenticated subject and optional scope against one persisted session boundary. */
|
|
1903
|
+
function offlineSessionManifestAllows(manifest, authSubject, scopeId) {
|
|
1904
|
+
if (!manifest || manifest.authSubject !== authSubject)
|
|
1905
|
+
return false;
|
|
1906
|
+
return scopeId === undefined || manifest.scopeIds.includes(scopeId);
|
|
1907
|
+
}
|
|
1872
1908
|
/** Owns activation and cleanup of the authenticated local-replica boundary. */
|
|
1873
1909
|
class OfflineSessionService {
|
|
1874
1910
|
constructor() {
|
|
@@ -2188,6 +2224,9 @@ class OfflineSyncService {
|
|
|
2188
2224
|
}
|
|
2189
2225
|
async #enqueue(request, options, generation) {
|
|
2190
2226
|
await this.initialize();
|
|
2227
|
+
if (this.#options.mode === 'readCacheOnly') {
|
|
2228
|
+
throw new Error('This offline provider is configured as a read-only cache and cannot enqueue commands.');
|
|
2229
|
+
}
|
|
2191
2230
|
const session = await this.#getLocalSession();
|
|
2192
2231
|
if (!session)
|
|
2193
2232
|
throw new Error('Cannot enqueue an offline command without an authenticated user');
|
|
@@ -2327,6 +2366,28 @@ class OfflineSyncService {
|
|
|
2327
2366
|
if (options.flush !== false && this.#network.connected())
|
|
2328
2367
|
this.#flushInBackground();
|
|
2329
2368
|
}
|
|
2369
|
+
/** Clears a retry backoff selected explicitly by the user and sends the durable command now. */
|
|
2370
|
+
async retryNow(commandId) {
|
|
2371
|
+
await this.initialize();
|
|
2372
|
+
this.#invalidateFlush();
|
|
2373
|
+
await this.#waitForSendingTransitions();
|
|
2374
|
+
await this.#restoreInterruptedCommands();
|
|
2375
|
+
const retried = await this.runSerializedReplicaMutation(async (repository) => {
|
|
2376
|
+
// Re-read only after every interrupted transport transition has settled.
|
|
2377
|
+
// An ACK may have removed the command while retryNow was waiting; never
|
|
2378
|
+
// resurrect such a command from an object captured before invalidation.
|
|
2379
|
+
const current = (await this.#readKnownCommands()).find((item) => item.commandId === commandId);
|
|
2380
|
+
if (!current)
|
|
2381
|
+
return false;
|
|
2382
|
+
if (current.state !== 'retry_wait') {
|
|
2383
|
+
throw new Error(`Offline command ${commandId} is not waiting for retry.`);
|
|
2384
|
+
}
|
|
2385
|
+
await repository.putCommand({ ...current, state: 'pending', retryAt: null, lastErrorCode: null });
|
|
2386
|
+
return true;
|
|
2387
|
+
});
|
|
2388
|
+
if (retried && this.#network.connected())
|
|
2389
|
+
await this.flush();
|
|
2390
|
+
}
|
|
2330
2391
|
async discardAllPending() {
|
|
2331
2392
|
await this.initialize();
|
|
2332
2393
|
this.#invalidateFlush();
|
|
@@ -3819,6 +3880,21 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.17", ngImpo
|
|
|
3819
3880
|
args: [{ providedIn: 'root' }]
|
|
3820
3881
|
}] });
|
|
3821
3882
|
|
|
3883
|
+
const READ_CACHE_ONLY_COMMAND_EXECUTOR = {
|
|
3884
|
+
execute: async () => {
|
|
3885
|
+
throw new Error('This offline provider is configured as a read-only cache.');
|
|
3886
|
+
},
|
|
3887
|
+
withServerRevision: (command) => command,
|
|
3888
|
+
};
|
|
3889
|
+
const READ_CACHE_ONLY_REPLICA_PULLER = {
|
|
3890
|
+
pull: async (request) => ({
|
|
3891
|
+
schemaVersion: request.schemaVersion,
|
|
3892
|
+
schemaHash: request.schemaHash,
|
|
3893
|
+
changes: [],
|
|
3894
|
+
nextCursor: request.cursor,
|
|
3895
|
+
hasMore: false,
|
|
3896
|
+
}),
|
|
3897
|
+
};
|
|
3822
3898
|
/**
|
|
3823
3899
|
* Provide the standard scoped offline runtime.
|
|
3824
3900
|
*
|
|
@@ -3828,12 +3904,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.17", ngImpo
|
|
|
3828
3904
|
* isolation.
|
|
3829
3905
|
*/
|
|
3830
3906
|
function provideOffline(options) {
|
|
3907
|
+
const synchronized = options.mode !== 'readCacheOnly';
|
|
3831
3908
|
return makeEnvironmentProviders([
|
|
3832
|
-
options.commandExecutor,
|
|
3833
|
-
options.replicaPuller,
|
|
3909
|
+
...(synchronized ? [options.commandExecutor, options.replicaPuller] : []),
|
|
3834
3910
|
{
|
|
3835
3911
|
provide: OFFLINE_KIT_OPTIONS,
|
|
3836
3912
|
useValue: {
|
|
3913
|
+
mode: options.mode ?? 'synchronized',
|
|
3837
3914
|
databaseName: options.databaseName,
|
|
3838
3915
|
createEncryptionKey: options.createEncryptionKey,
|
|
3839
3916
|
replicaSchema: options.replicaSchema,
|
|
@@ -3849,8 +3926,12 @@ function provideOffline(options) {
|
|
|
3849
3926
|
useFactory: () => selectOfflineRepository(Capacitor.getPlatform(), inject(IonicOfflineRepository), inject(SqliteOfflineRepository)),
|
|
3850
3927
|
},
|
|
3851
3928
|
{ provide: OFFLINE_SYNC_CONTEXT, useExisting: OfflineSessionService },
|
|
3852
|
-
|
|
3853
|
-
|
|
3929
|
+
synchronized
|
|
3930
|
+
? { provide: OFFLINE_COMMAND_EXECUTOR, useExisting: options.commandExecutor }
|
|
3931
|
+
: { provide: OFFLINE_COMMAND_EXECUTOR, useValue: READ_CACHE_ONLY_COMMAND_EXECUTOR },
|
|
3932
|
+
synchronized
|
|
3933
|
+
? { provide: OFFLINE_REPLICA_PULLER, useExisting: options.replicaPuller }
|
|
3934
|
+
: { provide: OFFLINE_REPLICA_PULLER, useValue: READ_CACHE_ONLY_REPLICA_PULLER },
|
|
3854
3935
|
...(options.commandHooks ? [options.commandHooks, { provide: OFFLINE_COMMAND_HOOKS, useExisting: options.commandHooks }] : []),
|
|
3855
3936
|
...options.requestPolicies.flatMap((policy) => provideOfflineRequestPolicy(policy)),
|
|
3856
3937
|
...(options.providers ?? []),
|
|
@@ -3919,5 +4000,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.17", ngImpo
|
|
|
3919
4000
|
* Generated bundle index. Do not edit.
|
|
3920
4001
|
*/
|
|
3921
4002
|
|
|
3922
|
-
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, nullable, offlineCommandLookupIdentity, offlineCommandTargetFromReplicaRow, offlineGeneratedReplicaIdentity, offlineInterceptor, offlineNaturalKeyFromValues, offlineNaturalReplicaIdentity, offlineReplicaRemoteIdentity, parseOfflineCommandIdentity, parseOfflinePrincipalId, projectOfflineReplicaValues, provideOffline, provideOfflineRequestPolicy, real, replicaAddressFromIdentity, selectOfflineRepository, serializeOfflineCommandIdentity, sha256OfflineReplicaSchema, text };
|
|
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 };
|
|
3923
4004
|
//# sourceMappingURL=rdlabo-ionic-angular-kit-offline.mjs.map
|