@rdlabo/ionic-angular-kit 21.5.10 → 21.5.11
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');
|
|
@@ -3819,6 +3858,21 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.17", ngImpo
|
|
|
3819
3858
|
args: [{ providedIn: 'root' }]
|
|
3820
3859
|
}] });
|
|
3821
3860
|
|
|
3861
|
+
const READ_CACHE_ONLY_COMMAND_EXECUTOR = {
|
|
3862
|
+
execute: async () => {
|
|
3863
|
+
throw new Error('This offline provider is configured as a read-only cache.');
|
|
3864
|
+
},
|
|
3865
|
+
withServerRevision: (command) => command,
|
|
3866
|
+
};
|
|
3867
|
+
const READ_CACHE_ONLY_REPLICA_PULLER = {
|
|
3868
|
+
pull: async (request) => ({
|
|
3869
|
+
schemaVersion: request.schemaVersion,
|
|
3870
|
+
schemaHash: request.schemaHash,
|
|
3871
|
+
changes: [],
|
|
3872
|
+
nextCursor: request.cursor,
|
|
3873
|
+
hasMore: false,
|
|
3874
|
+
}),
|
|
3875
|
+
};
|
|
3822
3876
|
/**
|
|
3823
3877
|
* Provide the standard scoped offline runtime.
|
|
3824
3878
|
*
|
|
@@ -3828,12 +3882,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.17", ngImpo
|
|
|
3828
3882
|
* isolation.
|
|
3829
3883
|
*/
|
|
3830
3884
|
function provideOffline(options) {
|
|
3885
|
+
const synchronized = options.mode !== 'readCacheOnly';
|
|
3831
3886
|
return makeEnvironmentProviders([
|
|
3832
|
-
options.commandExecutor,
|
|
3833
|
-
options.replicaPuller,
|
|
3887
|
+
...(synchronized ? [options.commandExecutor, options.replicaPuller] : []),
|
|
3834
3888
|
{
|
|
3835
3889
|
provide: OFFLINE_KIT_OPTIONS,
|
|
3836
3890
|
useValue: {
|
|
3891
|
+
mode: options.mode ?? 'synchronized',
|
|
3837
3892
|
databaseName: options.databaseName,
|
|
3838
3893
|
createEncryptionKey: options.createEncryptionKey,
|
|
3839
3894
|
replicaSchema: options.replicaSchema,
|
|
@@ -3849,8 +3904,12 @@ function provideOffline(options) {
|
|
|
3849
3904
|
useFactory: () => selectOfflineRepository(Capacitor.getPlatform(), inject(IonicOfflineRepository), inject(SqliteOfflineRepository)),
|
|
3850
3905
|
},
|
|
3851
3906
|
{ provide: OFFLINE_SYNC_CONTEXT, useExisting: OfflineSessionService },
|
|
3852
|
-
|
|
3853
|
-
|
|
3907
|
+
synchronized
|
|
3908
|
+
? { provide: OFFLINE_COMMAND_EXECUTOR, useExisting: options.commandExecutor }
|
|
3909
|
+
: { provide: OFFLINE_COMMAND_EXECUTOR, useValue: READ_CACHE_ONLY_COMMAND_EXECUTOR },
|
|
3910
|
+
synchronized
|
|
3911
|
+
? { provide: OFFLINE_REPLICA_PULLER, useExisting: options.replicaPuller }
|
|
3912
|
+
: { provide: OFFLINE_REPLICA_PULLER, useValue: READ_CACHE_ONLY_REPLICA_PULLER },
|
|
3854
3913
|
...(options.commandHooks ? [options.commandHooks, { provide: OFFLINE_COMMAND_HOOKS, useExisting: options.commandHooks }] : []),
|
|
3855
3914
|
...options.requestPolicies.flatMap((policy) => provideOfflineRequestPolicy(policy)),
|
|
3856
3915
|
...(options.providers ?? []),
|
|
@@ -3919,5 +3978,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.17", ngImpo
|
|
|
3919
3978
|
* Generated bundle index. Do not edit.
|
|
3920
3979
|
*/
|
|
3921
3980
|
|
|
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 };
|
|
3981
|
+
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
3982
|
//# sourceMappingURL=rdlabo-ionic-angular-kit-offline.mjs.map
|