@rdlabo/ionic-angular-kit 22.0.0-beta.pr99.sha950c83950d41 → 22.0.0
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 +26 -20
- package/docs/offline-realtime.md +116 -1
- package/docs/storage-overlays.md +21 -10
- package/fesm2022/rdlabo-ionic-angular-kit-offline.mjs +67 -81
- package/fesm2022/rdlabo-ionic-angular-kit-offline.mjs.map +1 -1
- package/package.json +1 -1
- package/types/rdlabo-ionic-angular-kit-offline.d.ts +23 -2
package/README.md
CHANGED
|
@@ -8,35 +8,39 @@ npm install @rdlabo/ionic-angular-kit
|
|
|
8
8
|
|
|
9
9
|
## Requirements
|
|
10
10
|
|
|
11
|
-
| Package
|
|
12
|
-
|
|
|
13
|
-
| Angular
|
|
14
|
-
| Ionic Angular
|
|
15
|
-
| RxJS
|
|
16
|
-
| Capacitor
|
|
17
|
-
| iOS/iPadOS deployment target
|
|
11
|
+
| Package | Supported version |
|
|
12
|
+
| ----------------------------------------------- | ----------------- |
|
|
13
|
+
| Angular | 21.x–22.x |
|
|
14
|
+
| Ionic Angular | 9.x |
|
|
15
|
+
| RxJS | 7.8.x |
|
|
16
|
+
| Capacitor Core, App, Haptics, Keyboard, Network | 7.x–8.x |
|
|
17
|
+
| iOS/iPadOS deployment target | 16.4 or later |
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
The core package declares `@ionic/storage-angular` and Capacitor Core, App, Haptics, Keyboard, and Network as required peers. Keep compatible versions installed even when an application uses only part of the core entry point. Native applications using `/offline` must additionally install and configure the `@capacitor-community/sqlite` major matching their Capacitor major; it is application-owned and is not installed by the kit.
|
|
20
|
+
|
|
21
|
+
Firebase, social login, Live Update, Preferences, Status Bar, in-app review, and printer/PDF dependencies are optional feature peers. Install only the dependencies used by the selected secondary entry points and follow each plugin's own compatibility range; some optional plugins support only Capacitor 8.
|
|
20
22
|
|
|
21
23
|
## Entry points
|
|
22
24
|
|
|
23
|
-
| Import | Responsibility
|
|
24
|
-
| ----------------------------------------- |
|
|
25
|
-
| `@rdlabo/ionic-angular-kit` | Storage, overlays, guards, HTTP, realtime, directives, keyboard, and utilities
|
|
26
|
-
| `@rdlabo/ionic-angular-kit/offline` | Scoped local replica, outbox, pull, replay, and request policies
|
|
27
|
-
| `@rdlabo/ionic-angular-kit/theme` | Persisted light/dark theme and native status bar sync
|
|
28
|
-
| `@rdlabo/ionic-angular-kit/forms` | Ionic error text and state classes for Angular Signal Forms
|
|
29
|
-
| `@rdlabo/ionic-angular-kit/review` | Throttled native in-app review requests
|
|
30
|
-
| `@rdlabo/ionic-angular-kit/printer` | DOM-to-PNG, Brother label, and PDF helpers
|
|
31
|
-
| `@rdlabo/ionic-angular-kit/auth-firebase` | Firebase dependency wiring and authentication flows
|
|
32
|
-
| `@rdlabo/ionic-angular-kit/app-update` | Atomic Angular service-worker update transitions
|
|
33
|
-
| `@rdlabo/ionic-angular-kit/live-update` | Capawesome Live Update readiness provider
|
|
25
|
+
| Import | Responsibility |
|
|
26
|
+
| ----------------------------------------- | ---------------------------------------------------------------------------------- |
|
|
27
|
+
| `@rdlabo/ionic-angular-kit` | Storage, overlays, guards, HTTP, realtime, directives, keyboard, and utilities |
|
|
28
|
+
| `@rdlabo/ionic-angular-kit/offline` | **Experimental.** Scoped local replica, outbox, pull, replay, and request policies |
|
|
29
|
+
| `@rdlabo/ionic-angular-kit/theme` | Persisted light/dark theme and native status bar sync |
|
|
30
|
+
| `@rdlabo/ionic-angular-kit/forms` | Ionic error text and state classes for Angular Signal Forms |
|
|
31
|
+
| `@rdlabo/ionic-angular-kit/review` | Throttled native in-app review requests |
|
|
32
|
+
| `@rdlabo/ionic-angular-kit/printer` | DOM-to-PNG, Brother label, and PDF helpers |
|
|
33
|
+
| `@rdlabo/ionic-angular-kit/auth-firebase` | Firebase dependency wiring and authentication flows |
|
|
34
|
+
| `@rdlabo/ionic-angular-kit/app-update` | Atomic Angular service-worker update transitions |
|
|
35
|
+
| `@rdlabo/ionic-angular-kit/live-update` | Capawesome Live Update readiness provider |
|
|
34
36
|
|
|
35
37
|
Secondary entry points isolate optional native and SDK dependencies from the core bundle.
|
|
36
38
|
|
|
39
|
+
The entire `/offline` entry point is experimental and is not covered by the kit's SemVer compatibility guarantee. Its public APIs, persistence schema, and synchronization behavior may change incompatibly in a minor or patch release before stabilization. Pin the kit to an exact version when adopting it, and review the migration guide before every upgrade.
|
|
40
|
+
|
|
37
41
|
## Configure only what you use
|
|
38
42
|
|
|
39
|
-
Most features expose a provider whose callbacks keep routes, copy, credentials, and application side effects outside the kit. Start with [Storage and Overlays](https://docs.rdlabo.dev/projects/ionic-angular-kit/docs/storage-overlays), then add authentication, offline, or native features as your app needs them.
|
|
43
|
+
Most features expose a provider whose callbacks keep routes, copy, credentials, and application side effects outside the kit. Start with [Storage and Overlays](https://docs.rdlabo.dev/projects/ionic-angular-kit/docs/storage-overlays), then add authentication, offline, or native features as your app needs them. The [Offline and Realtime](https://docs.rdlabo.dev/projects/ionic-angular-kit/docs/offline-realtime) guide includes the required SQLite connection, provider/interceptor order, read strategies, durable Outbox flow, and repository concurrency rules.
|
|
40
44
|
|
|
41
45
|
## Documentation
|
|
42
46
|
|
|
@@ -46,5 +50,7 @@ Most features expose a provider whose callbacks keep routes, copy, credentials,
|
|
|
46
50
|
- [Optional Features](https://docs.rdlabo.dev/projects/ionic-angular-kit/docs/optional-features)
|
|
47
51
|
|
|
48
52
|
<!-- rdlabo-docs-omit -->
|
|
53
|
+
|
|
49
54
|
**Full documentation:** [https://docs.rdlabo.dev/projects/ionic-angular-kit](https://docs.rdlabo.dev/projects/ionic-angular-kit)
|
|
55
|
+
|
|
50
56
|
<!-- /rdlabo-docs-omit -->
|
package/docs/offline-realtime.md
CHANGED
|
@@ -1,9 +1,67 @@
|
|
|
1
1
|
## Scoped offline runtime
|
|
2
2
|
|
|
3
|
+
> **Experimental:** The entire `@rdlabo/ionic-angular-kit/offline` entry point is experimental and is not covered by the kit's SemVer compatibility guarantee. Its public APIs, persistence schema, and synchronization behavior may change incompatibly in a minor or patch release before stabilization. Pin the kit to an exact version when adopting it, and review the migration guide before every upgrade.
|
|
4
|
+
|
|
3
5
|
The `/offline` entry point provides a user- and partition-scoped local replica, durable outbox, cursor-based delta pull, aggregate-ordered replay, optimistic mutation policies, and request-policy interception.
|
|
4
6
|
|
|
5
7
|
Use `mode: 'readCacheOnly'` for external-source or HTTP caches. Synchronized mode uses encrypted `@capacitor-community/sqlite` on iOS and Android; it fails fast on the web because the current runtime has no cross-tab synchronization lock.
|
|
6
8
|
|
|
9
|
+
### Install and provide the runtime
|
|
10
|
+
|
|
11
|
+
Provide Ionic Storage once for the kit's storage infrastructure. Web read-cache installations also use it as the offline repository. Native synchronized applications additionally own the Community SQLite connection passed to the kit. The SQLite install and native sync below are required only for synchronized iOS and Android applications:
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npm install @ionic/storage-angular @capacitor-community/sqlite@^8
|
|
15
|
+
npx cap sync
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
The SQLite plugin major must match Capacitor: use `@capacitor-community/sqlite@^7` in a Capacitor 7 application and `@^8` in a Capacitor 8 application.
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { provideHttpClient, withInterceptors } from '@angular/common/http';
|
|
22
|
+
import { importProvidersFrom } from '@angular/core';
|
|
23
|
+
import { CapacitorSQLite, SQLiteConnection } from '@capacitor-community/sqlite';
|
|
24
|
+
import { IonicStorageModule } from '@ionic/storage-angular';
|
|
25
|
+
import { kitAuthInterceptor } from '@rdlabo/ionic-angular-kit';
|
|
26
|
+
import { offlineInterceptor, provideOffline } from '@rdlabo/ionic-angular-kit/offline';
|
|
27
|
+
|
|
28
|
+
const sqliteConnection = new SQLiteConnection(CapacitorSQLite);
|
|
29
|
+
|
|
30
|
+
export const appConfig = {
|
|
31
|
+
providers: [
|
|
32
|
+
importProvidersFrom(IonicStorageModule.forRoot({ name: '__kit_storage' })),
|
|
33
|
+
provideHttpClient(withInterceptors([offlineInterceptor, kitAuthInterceptor])),
|
|
34
|
+
provideOffline({
|
|
35
|
+
databaseName: 'product_offline',
|
|
36
|
+
replicaSchema,
|
|
37
|
+
sqliteConnection,
|
|
38
|
+
createEncryptionKey: () => secureKeyStore.getOrCreateOfflineKey(),
|
|
39
|
+
requestPolicies: [ProductReadPolicy],
|
|
40
|
+
mutationPolicies: [ProductMutationPolicy],
|
|
41
|
+
commandExecutor: ProductCommandExecutor,
|
|
42
|
+
replicaPuller: ProductReplicaPuller,
|
|
43
|
+
aggregateIntentProjector: ProductAggregateIntentProjector,
|
|
44
|
+
}),
|
|
45
|
+
],
|
|
46
|
+
};
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Register `offlineInterceptor` before `kitAuthInterceptor`. Product adapters own URL and DTO mapping, replica schemas, encryption-key storage, server pull/command protocols, and optimistic projection. The kit owns persistence, session isolation, FIFO ordering, retries, and reconciliation. Set `databaseEncryption: false` only for an intentional plaintext native database; encryption is otherwise the default and requires `createEncryptionKey` on first open.
|
|
50
|
+
|
|
51
|
+
For `mode: 'readCacheOnly'`, omit mutation policies, the command executor, replica puller, and aggregate intent projector. Web supports this read-cache mode through Ionic Storage. Web synchronized mode is rejected until its repository can provide cross-context locking.
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
provideOffline({
|
|
55
|
+
mode: 'readCacheOnly',
|
|
56
|
+
databaseName: 'product_cache',
|
|
57
|
+
databaseEncryption: false,
|
|
58
|
+
replicaSchema,
|
|
59
|
+
requestPolicies: [ProductReadPolicy],
|
|
60
|
+
});
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
The web read-cache configuration does not import or pass Community SQLite. `databaseEncryption: false` is explicit because SQLCipher applies only to the native repository.
|
|
64
|
+
|
|
7
65
|
Cold-start offline access restores only a manifest bound to a non-null authentication-provider subject. Remote work follows this order:
|
|
8
66
|
|
|
9
67
|
1. Prepare the verified remote session.
|
|
@@ -13,6 +71,7 @@ Cold-start offline access restores only a manifest bound to a non-null authentic
|
|
|
13
71
|
`createOfflineAuthBridge()` connects this ordering to `provideKitAuth()` while leaving consent, error UI, and credential exchange in the app.
|
|
14
72
|
|
|
15
73
|
```ts
|
|
74
|
+
import { provideKitAuth } from '@rdlabo/ionic-angular-kit';
|
|
16
75
|
import { createOfflineAuthBridge, isOfflineFallbackError } from '@rdlabo/ionic-angular-kit/offline';
|
|
17
76
|
|
|
18
77
|
provideKitAuth(() => ({
|
|
@@ -20,7 +79,7 @@ provideKitAuth(() => ({
|
|
|
20
79
|
...createOfflineAuthBridge({
|
|
21
80
|
exchange: async (context) => exchangeCredential(context),
|
|
22
81
|
currentAuthSubject: () => auth.currentSubject(),
|
|
23
|
-
isUnavailableError,
|
|
82
|
+
isUnavailableError: isOfflineFallbackError,
|
|
24
83
|
availability: () => auth.authorityAvailable$,
|
|
25
84
|
}),
|
|
26
85
|
redirects,
|
|
@@ -29,6 +88,62 @@ provideKitAuth(() => ({
|
|
|
29
88
|
|
|
30
89
|
On explicit sign-out, clear `KitAuthAccessService` first, then await offline session cleanup so in-flight leases are invalidated before persisted user data is removed.
|
|
31
90
|
|
|
91
|
+
### Read request strategies
|
|
92
|
+
|
|
93
|
+
An `OfflineRequestPolicy` resolves a matched GET to `kind: 'read'`, a `readLocal()` function, and an optional shared `projectResponse()` function. `readStrategy` controls settlement:
|
|
94
|
+
|
|
95
|
+
| Strategy | Behavior |
|
|
96
|
+
| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
97
|
+
| `network-first` | Default. Uses transport first and falls back to the local response for an offline/unavailable transport error. |
|
|
98
|
+
| `local-first` | Starts local and remote work together, emits a usable local response first, then emits remote revalidation. |
|
|
99
|
+
| `fastest-first` | Emits whichever usable response settles first. A local winner is followed by remote revalidation; a remote winner cancels the slower local read. |
|
|
100
|
+
| `local-only` | Never starts HTTP transport. Use it for provisional identities that cannot exist remotely. |
|
|
101
|
+
|
|
102
|
+
`local-first` and a locally winning `fastest-first` can emit twice. Keep the HTTP observable subscribed through revalidation; `firstValueFrom()` and `take(1)` cancel the transport after the first emission. Use `offlineReadEmission()` and `shouldCommitOfflineCollection()` when UI state needs to distinguish a complete remote collection from an incomplete empty local snapshot.
|
|
103
|
+
|
|
104
|
+
`projectResponse(response, source)` runs for both remote and local responses. Persist only when `source === 'remote'`. Set `serializeResponseProjection: true` when the projector performs read-only derivation that must wait behind replica mutations. Do not enable it when the projector starts a replica mutation itself; use `OfflineSyncService.runSerializedReplicaMutation()` for a read/derive/write sequence instead.
|
|
105
|
+
|
|
106
|
+
### Durable mutations and immediate generated creates
|
|
107
|
+
|
|
108
|
+
Mutation policies prepare the optimistic `HttpResponse`; the product implementation should enqueue the corresponding durable intent before returning it. `enqueue()` generates a UUID by default. Supply a stable `commandId` when product code must correlate the durable intent with surrounding work or immediately send a newly created generated identity. Kit preserves that ID across transport retries.
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
import type { OfflineGeneratedCommandLocator } from '@rdlabo/ionic-angular-kit/offline';
|
|
112
|
+
|
|
113
|
+
const commandId = crypto.randomUUID();
|
|
114
|
+
const localId = crypto.randomUUID();
|
|
115
|
+
|
|
116
|
+
await offlineSync.enqueue(
|
|
117
|
+
{
|
|
118
|
+
commandId,
|
|
119
|
+
scopeId,
|
|
120
|
+
aggregateType: 'photo',
|
|
121
|
+
identity: { kind: 'generated', localId },
|
|
122
|
+
operation: 'create',
|
|
123
|
+
payload: createPayload,
|
|
124
|
+
},
|
|
125
|
+
{ flush: false },
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
const locator = {
|
|
129
|
+
scopeId,
|
|
130
|
+
sourceKey: 'photo',
|
|
131
|
+
localId,
|
|
132
|
+
} satisfies OfflineGeneratedCommandLocator;
|
|
133
|
+
|
|
134
|
+
const remoteId = await offlineSync.sendGeneratedCommandNow(commandId, locator);
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
The second argument has type `OfflineGeneratedCommandLocator`. `sendGeneratedCommandNow()` is deliberately limited to the first pending intent of a new generated aggregate with no confirmed baseline or remote ID. It skips the normal pre-send pull and commits the local acknowledgement. When it obtains a confirmed remote ID, it schedules authoritative pull reconciliation in the background. It returns `null` when transport is unavailable or no confirmed ID is produced. A terminal `blocked_auth`, `rejected`, or `conflict` result throws `OfflineImmediateCommandRejectedError`. Existing aggregates and later intents must use `flush()` so the pre-pull conflict barrier remains in place.
|
|
138
|
+
|
|
139
|
+
Command payloads must be losslessly JSON-serializable. Caller-owned command IDs must contain 1–255 characters and must not be reused during the application/server idempotency-retention period. Kit can reject only collisions with commands that are still retained locally; the server may still deduplicate a reused ID after its local command has been reconciled and removed.
|
|
140
|
+
|
|
141
|
+
### Repository consistency boundary
|
|
142
|
+
|
|
143
|
+
Treat `OfflineSyncService` as the product mutation owner. For a product read/derive/write operation, use `runSerializedReplicaMutation()`. Inside its callback, use only the supplied repository and finish the write with that repository's `transactReplica()`; do not start a nested `OfflineSyncService` mutation or another coordinator lane. Commit replica rows, Outbox commands, cursors, and pull-attention changes together in that transaction.
|
|
144
|
+
|
|
145
|
+
For a read-only multi-query snapshot, use `repository.runReadSnapshot()` and perform all reads through the supplied reader. Do not mutate the repository or nest another `runReadSnapshot()` inside that callback. Direct `replaceCommand()`, `removeCommand()`, `putPullAttention()`, and `removePullAttention()` repository methods are deprecated; use the corresponding `putCommands`, `removeCommandIds`, `putPullAttentions`, and `removePullAttentions` fields of `transactReplica()`.
|
|
146
|
+
|
|
32
147
|
### Lazy authenticated routes
|
|
33
148
|
|
|
34
149
|
Use `provideRouteScopedOffline()` when the offline runtime and product schema must not enter the
|
package/docs/storage-overlays.md
CHANGED
|
@@ -3,20 +3,34 @@
|
|
|
3
3
|
Provide Ionic Storage once. `KitStorageService` initializes it lazily and every public operation waits for that initialization, so writes made immediately after service creation are not dropped.
|
|
4
4
|
|
|
5
5
|
```ts
|
|
6
|
-
import { importProvidersFrom } from '@angular/core';
|
|
6
|
+
import { importProvidersFrom, type ApplicationConfig } from '@angular/core';
|
|
7
7
|
import { IonicStorageModule } from '@ionic/storage-angular';
|
|
8
8
|
|
|
9
9
|
export const appConfig: ApplicationConfig = {
|
|
10
|
-
providers: [importProvidersFrom(IonicStorageModule.
|
|
10
|
+
providers: [importProvidersFrom(IonicStorageModule.forRoot({ name: '__mydb' }))],
|
|
11
11
|
};
|
|
12
12
|
```
|
|
13
13
|
|
|
14
14
|
```ts
|
|
15
|
-
|
|
15
|
+
import { inject, Injectable } from '@angular/core';
|
|
16
|
+
import { KitStorageService } from '@rdlabo/ionic-angular-kit';
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
@Injectable({ providedIn: 'root' })
|
|
19
|
+
export class TokenStore {
|
|
20
|
+
readonly #storage = inject(KitStorageService);
|
|
21
|
+
|
|
22
|
+
async save(token: string): Promise<void> {
|
|
23
|
+
await this.#storage.set('token', token);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
get(): Promise<string | null> {
|
|
27
|
+
return this.#storage.get<string>('token');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
remove(): Promise<void> {
|
|
31
|
+
return this.#storage.remove('token');
|
|
32
|
+
}
|
|
33
|
+
}
|
|
20
34
|
```
|
|
21
35
|
|
|
22
36
|
`get<T>()` returns `null` for a missing key. `kitClearStoragePreservingKeys()` clears application data while restoring selected values such as the last authentication email or theme.
|
|
@@ -40,10 +54,7 @@ export class DetailPage {
|
|
|
40
54
|
readonly item = input.required<Item>();
|
|
41
55
|
}
|
|
42
56
|
|
|
43
|
-
export const launchDetailPage = (
|
|
44
|
-
overlay: KitOverlayController,
|
|
45
|
-
props: { item: Item },
|
|
46
|
-
): Promise<DetailResult | undefined> =>
|
|
57
|
+
export const launchDetailPage = (overlay: KitOverlayController, props: { item: Item }): Promise<DetailResult | undefined> =>
|
|
47
58
|
overlay.presentModal(DetailPage, props, { backdropDismiss: false });
|
|
48
59
|
```
|
|
49
60
|
|
|
@@ -1198,29 +1198,21 @@ class IonicOfflineRepository {
|
|
|
1198
1198
|
return commands;
|
|
1199
1199
|
});
|
|
1200
1200
|
}
|
|
1201
|
+
/** @deprecated Use {@link transactReplica} with `putCommands`. */
|
|
1201
1202
|
replaceCommand(command) {
|
|
1202
1203
|
return this.putCommand(command);
|
|
1203
1204
|
}
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
delete commands[commandId];
|
|
1208
|
-
return commands;
|
|
1209
|
-
});
|
|
1205
|
+
/** @deprecated Use {@link transactReplica} with `removeCommandIds`. */
|
|
1206
|
+
removeCommand(commandId) {
|
|
1207
|
+
return this.transactReplica({ removeCommandIds: [commandId] });
|
|
1210
1208
|
}
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
attentions[this.#cursorKey(attention)] = attention;
|
|
1215
|
-
return attentions;
|
|
1216
|
-
});
|
|
1209
|
+
/** @deprecated Use {@link transactReplica} with `putPullAttentions`. */
|
|
1210
|
+
putPullAttention(attention) {
|
|
1211
|
+
return this.transactReplica({ putPullAttentions: [attention] });
|
|
1217
1212
|
}
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
delete attentions[this.#cursorKey(scope)];
|
|
1222
|
-
return attentions;
|
|
1223
|
-
});
|
|
1213
|
+
/** @deprecated Use {@link transactReplica} with `removePullAttentions`. */
|
|
1214
|
+
removePullAttention(scope) {
|
|
1215
|
+
return this.transactReplica({ removePullAttentions: [scope] });
|
|
1224
1216
|
}
|
|
1225
1217
|
async clearUser(userId) {
|
|
1226
1218
|
await this.initialize();
|
|
@@ -1821,7 +1813,7 @@ class OfflineReplicaMutationCoordinator {
|
|
|
1821
1813
|
return this.#enqueue(() => {
|
|
1822
1814
|
if (!this.#repository)
|
|
1823
1815
|
throw new Error('Offline repository is not configured.');
|
|
1824
|
-
const atomicMutation = this.#repository
|
|
1816
|
+
const atomicMutation = this.#repository[OFFLINE_REPOSITORY_ATOMIC_MUTATION];
|
|
1825
1817
|
return atomicMutation ? atomicMutation.call(this.#repository, operation) : operation(this.#repository);
|
|
1826
1818
|
});
|
|
1827
1819
|
}
|
|
@@ -2255,7 +2247,7 @@ class OfflineReplicaPullService {
|
|
|
2255
2247
|
{ putRows, removeRows },
|
|
2256
2248
|
{ putRows: projection?.putRows ?? [], removeRows: projection?.removeRows ?? [] },
|
|
2257
2249
|
]);
|
|
2258
|
-
const rematerialized = await this.#rematerializePendingAggregates(
|
|
2250
|
+
const rematerialized = await this.#rematerializePendingAggregates(userCommands, scopeCommands, confirmedAndProjected, putCommands, removeCommandIds, rematerializeAfter);
|
|
2259
2251
|
const finalRows = this.#mergeRowMutations([confirmedAndProjected, rematerialized]);
|
|
2260
2252
|
const removedCommands = [...removeCommandIds]
|
|
2261
2253
|
.map((commandId) => userCommands.find((command) => command.commandId === commandId) ??
|
|
@@ -2396,7 +2388,7 @@ class OfflineReplicaPullService {
|
|
|
2396
2388
|
this.#assertPullChange(change, index);
|
|
2397
2389
|
}
|
|
2398
2390
|
}
|
|
2399
|
-
async #rematerializePendingAggregates(
|
|
2391
|
+
async #rematerializePendingAggregates(userCommands, scopeCommands, currentRows, putCommands, removeCommandIds, seeds) {
|
|
2400
2392
|
const remaining = [...userCommands, ...scopeCommands]
|
|
2401
2393
|
.filter((command, index, all) => all.findIndex((candidate) => candidate.commandId === command.commandId) === index)
|
|
2402
2394
|
.filter((command) => !removeCommandIds.has(command.commandId))
|
|
@@ -2460,7 +2452,6 @@ class OfflineReplicaPullService {
|
|
|
2460
2452
|
putRows.push(...(mutations.putRows ?? []));
|
|
2461
2453
|
removeRows.push(...(mutations.removeRows ?? []));
|
|
2462
2454
|
}
|
|
2463
|
-
void scope;
|
|
2464
2455
|
return { putRows, removeRows };
|
|
2465
2456
|
}
|
|
2466
2457
|
async #overlayBaseRow(command, overlay, removed) {
|
|
@@ -3272,11 +3263,11 @@ class OfflineSyncService {
|
|
|
3272
3263
|
const scope = { userId, scopeId: request.scopeId };
|
|
3273
3264
|
this.noteScope(scope);
|
|
3274
3265
|
const commandIdentity = offlineCommandLookupIdentity(request.identity);
|
|
3275
|
-
const normalized = await this.#normalizeEnqueueRequest(scope, request, commandIdentity, repository);
|
|
3276
3266
|
const commandId = request.commandId ?? crypto.randomUUID();
|
|
3277
3267
|
if (typeof commandId !== 'string' || commandId.length === 0 || commandId.length > 255) {
|
|
3278
3268
|
throw new Error('Offline command id must contain between 1 and 255 characters.');
|
|
3279
3269
|
}
|
|
3270
|
+
assertOfflinePayload(request.payload);
|
|
3280
3271
|
const sourceKey = this.#hooks.entityType(request);
|
|
3281
3272
|
const localOnlyFootprint = this.#normalizedLocalOnlyFootprint(scope, request.localOnlyFootprint);
|
|
3282
3273
|
if (replaced)
|
|
@@ -3288,9 +3279,9 @@ class OfflineSyncService {
|
|
|
3288
3279
|
sourceKey,
|
|
3289
3280
|
identity: commandIdentity,
|
|
3290
3281
|
operation: request.operation,
|
|
3291
|
-
payload:
|
|
3282
|
+
payload: request.payload,
|
|
3292
3283
|
replicaMutation: request.replicaMutation ?? 'upsert',
|
|
3293
|
-
baseRevision:
|
|
3284
|
+
baseRevision: request.baseRevision ?? null,
|
|
3294
3285
|
state: 'pending',
|
|
3295
3286
|
attempts: 0,
|
|
3296
3287
|
retryAt: null,
|
|
@@ -3307,21 +3298,23 @@ class OfflineSyncService {
|
|
|
3307
3298
|
canonicalOfflineCommandIdentity(replaced.identity) !== canonicalOfflineCommandIdentity(command.identity))) {
|
|
3308
3299
|
throw new Error('Offline replacement command must address the same aggregate and replica identity.');
|
|
3309
3300
|
}
|
|
3310
|
-
const
|
|
3311
|
-
const schema = this.#entitySchema(entityType);
|
|
3301
|
+
const schema = this.#entitySchema(sourceKey);
|
|
3312
3302
|
if (schema.identity.kind === 'localOnly') {
|
|
3313
|
-
throw new Error(`Offline replica source "${
|
|
3303
|
+
throw new Error(`Offline replica source "${sourceKey}" is local-only and cannot be added to the Outbox.`);
|
|
3314
3304
|
}
|
|
3315
3305
|
if (schema.identity.kind === 'generated' && request.identity.kind !== 'generated') {
|
|
3316
|
-
throw new Error(`Offline replica source "${
|
|
3306
|
+
throw new Error(`Offline replica source "${sourceKey}" requires generated identity.`);
|
|
3317
3307
|
}
|
|
3318
3308
|
if (schema.identity.kind === 'naturalKey' && request.identity.kind !== 'natural') {
|
|
3319
|
-
throw new Error(`Offline replica source "${
|
|
3309
|
+
throw new Error(`Offline replica source "${sourceKey}" requires natural identity.`);
|
|
3320
3310
|
}
|
|
3321
3311
|
if (request.replicaMutation === 'delete' && !repository.getReplicaRowIncludingPendingDelete) {
|
|
3322
3312
|
throw new Error('Offline repository does not support durable replica delete tombstones.');
|
|
3323
3313
|
}
|
|
3324
|
-
const existing = await this.#getReplicaRowForSync(scope,
|
|
3314
|
+
const existing = await this.#getReplicaRowForSync(scope, sourceKey, commandIdentity, repository);
|
|
3315
|
+
if (existing?.serverRevision != null && existing.serverRevision !== command.baseRevision) {
|
|
3316
|
+
command = { ...command, baseRevision: existing.serverRevision };
|
|
3317
|
+
}
|
|
3325
3318
|
const generatedIdentity = request.identity.kind === 'generated' ? request.identity : null;
|
|
3326
3319
|
const initialRemoteId = this.#initialRemoteId(schema, existing?.identity.kind === 'generated' ? existing.identity.remoteId : null, generatedIdentity?.remoteId);
|
|
3327
3320
|
this.#assertRemoteIdHint(schema, existing?.identity.kind === 'generated' ? existing.identity.remoteId : null, generatedIdentity?.remoteIdHint);
|
|
@@ -3334,7 +3327,7 @@ class OfflineSyncService {
|
|
|
3334
3327
|
request.identity.kind === 'natural' &&
|
|
3335
3328
|
canonicalOfflineRemoteIdentity(schema, { naturalKey: request.identity.naturalKey }) !==
|
|
3336
3329
|
canonicalOfflineRemoteIdentity(schema, { naturalKey: naturalKey })) {
|
|
3337
|
-
throw new Error(`Offline command naturalKey must match replica identity for "${
|
|
3330
|
+
throw new Error(`Offline command naturalKey must match replica identity for "${sourceKey}".`);
|
|
3338
3331
|
}
|
|
3339
3332
|
const remoteIdentity = schema.identity.kind === 'generated'
|
|
3340
3333
|
? initialRemoteId === null
|
|
@@ -3349,11 +3342,11 @@ class OfflineSyncService {
|
|
|
3349
3342
|
canonicalOfflineRemoteIdentity(schema, {
|
|
3350
3343
|
naturalKey: existing.identity.kind === 'natural' ? existing.identity.naturalKey : offlineNaturalKeyFromValues(schema, existing.values),
|
|
3351
3344
|
}) !== canonicalValuesKey) {
|
|
3352
|
-
throw new Error(`Offline replica naturalKey is immutable and must match command identity for "${
|
|
3345
|
+
throw new Error(`Offline replica naturalKey is immutable and must match command identity for "${sourceKey}".`);
|
|
3353
3346
|
}
|
|
3354
3347
|
}
|
|
3355
3348
|
if (remoteIdentity !== null) {
|
|
3356
|
-
const mapped = await repository.getReplicaRowByRemoteIdentity(scope,
|
|
3349
|
+
const mapped = await repository.getReplicaRowByRemoteIdentity(scope, sourceKey, remoteIdentity);
|
|
3357
3350
|
if (mapped !== null && !commandIdentityMatchesReplicaRow(schema, mapped, commandIdentity)) {
|
|
3358
3351
|
if ('remoteId' in remoteIdentity) {
|
|
3359
3352
|
throw new Error(`Offline replica remote id ${String(remoteIdentity.remoteId)} is already mapped to another row.`);
|
|
@@ -3361,7 +3354,6 @@ class OfflineSyncService {
|
|
|
3361
3354
|
throw new Error(`Offline replica remote identity is already mapped to another row.`);
|
|
3362
3355
|
}
|
|
3363
3356
|
}
|
|
3364
|
-
this.#canonicalJson(normalized.payload);
|
|
3365
3357
|
const seedBaseRow = existing
|
|
3366
3358
|
? undefined
|
|
3367
3359
|
: request.identity.kind === 'generated'
|
|
@@ -4103,15 +4095,6 @@ class OfflineSyncService {
|
|
|
4103
4095
|
}
|
|
4104
4096
|
return true;
|
|
4105
4097
|
}
|
|
4106
|
-
async #normalizeEnqueueRequest(scope, request, commandIdentity, repository) {
|
|
4107
|
-
let baseRevision = request.baseRevision ?? null;
|
|
4108
|
-
const sourceKey = this.#hooks.entityType(request);
|
|
4109
|
-
const row = await this.#getReplicaRowForSync(scope, sourceKey, commandIdentity, repository);
|
|
4110
|
-
if (row?.serverRevision != null && row.serverRevision !== baseRevision) {
|
|
4111
|
-
baseRevision = row.serverRevision;
|
|
4112
|
-
}
|
|
4113
|
-
return { payload: request.payload, baseRevision };
|
|
4114
|
-
}
|
|
4115
4098
|
async #completeCommand(commands, command, result, generation) {
|
|
4116
4099
|
return this.#serializeReplicaMutation((repository) => this.#completeCommandLocked(commands, command, result, generation, repository));
|
|
4117
4100
|
}
|
|
@@ -4617,27 +4600,6 @@ class OfflineSyncService {
|
|
|
4617
4600
|
async #waitForSendingTransitions() {
|
|
4618
4601
|
await Promise.allSettled([...this.#sendingTransitions, ...this.#commandSendTransitions.values()]);
|
|
4619
4602
|
}
|
|
4620
|
-
#canonicalJson(value) {
|
|
4621
|
-
if (Array.isArray(value))
|
|
4622
|
-
return `[${value.map((item) => this.#canonicalJson(item)).join(',')}]`;
|
|
4623
|
-
if (value !== null && typeof value === 'object') {
|
|
4624
|
-
if (Object.getPrototypeOf(value) !== Object.prototype) {
|
|
4625
|
-
throw new OfflinePayloadValidationError();
|
|
4626
|
-
}
|
|
4627
|
-
return `{${Object.entries(value)
|
|
4628
|
-
.sort(([left], [right]) => (left < right ? -1 : left > right ? 1 : 0))
|
|
4629
|
-
.map(([key, item]) => `${JSON.stringify(key)}:${this.#canonicalJson(item)}`)
|
|
4630
|
-
.join(',')}}`;
|
|
4631
|
-
}
|
|
4632
|
-
if (typeof value === 'number' && !Number.isFinite(value)) {
|
|
4633
|
-
throw new OfflinePayloadValidationError();
|
|
4634
|
-
}
|
|
4635
|
-
const serialized = JSON.stringify(value);
|
|
4636
|
-
if (typeof serialized !== 'string') {
|
|
4637
|
-
throw new OfflinePayloadValidationError();
|
|
4638
|
-
}
|
|
4639
|
-
return serialized;
|
|
4640
|
-
}
|
|
4641
4603
|
#scopeKey(scope) {
|
|
4642
4604
|
return `${canonicalOfflinePrincipalId(scope.userId)}:${scope.scopeId}`;
|
|
4643
4605
|
}
|
|
@@ -4648,6 +4610,26 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.3", ngImpor
|
|
|
4648
4610
|
type: Injectable,
|
|
4649
4611
|
args: [{ providedIn: 'root' }]
|
|
4650
4612
|
}], ctorParameters: () => [] });
|
|
4613
|
+
function assertOfflinePayload(value, ancestors = new Set()) {
|
|
4614
|
+
if (value === null || typeof value === 'string' || typeof value === 'boolean')
|
|
4615
|
+
return;
|
|
4616
|
+
if (typeof value === 'number') {
|
|
4617
|
+
if (Number.isFinite(value))
|
|
4618
|
+
return;
|
|
4619
|
+
throw new OfflinePayloadValidationError();
|
|
4620
|
+
}
|
|
4621
|
+
if (typeof value !== 'object' || ancestors.has(value)) {
|
|
4622
|
+
throw new OfflinePayloadValidationError();
|
|
4623
|
+
}
|
|
4624
|
+
if (!Array.isArray(value) && Object.getPrototypeOf(value) !== Object.prototype) {
|
|
4625
|
+
throw new OfflinePayloadValidationError();
|
|
4626
|
+
}
|
|
4627
|
+
ancestors.add(value);
|
|
4628
|
+
const items = Array.isArray(value) ? value : Object.values(value);
|
|
4629
|
+
for (const item of items)
|
|
4630
|
+
assertOfflinePayload(item, ancestors);
|
|
4631
|
+
ancestors.delete(value);
|
|
4632
|
+
}
|
|
4651
4633
|
function compareOfflineCommands(left, right) {
|
|
4652
4634
|
return left.createdAt - right.createdAt || (left.commandId < right.commandId ? -1 : left.commandId > right.commandId ? 1 : 0);
|
|
4653
4635
|
}
|
|
@@ -6106,26 +6088,21 @@ class SqliteOfflineRepository {
|
|
|
6106
6088
|
async putCommand(command) {
|
|
6107
6089
|
await this.#queueWrite((databaseId) => this.#putCommand(databaseId, command));
|
|
6108
6090
|
}
|
|
6091
|
+
/** @deprecated Use {@link transactReplica} with `putCommands`. */
|
|
6109
6092
|
replaceCommand(command) {
|
|
6110
6093
|
return this.putCommand(command);
|
|
6111
6094
|
}
|
|
6112
|
-
|
|
6113
|
-
|
|
6095
|
+
/** @deprecated Use {@link transactReplica} with `removeCommandIds`. */
|
|
6096
|
+
removeCommand(commandId) {
|
|
6097
|
+
return this.transactReplica({ removeCommandIds: [commandId] });
|
|
6114
6098
|
}
|
|
6115
|
-
|
|
6116
|
-
|
|
6117
|
-
|
|
6118
|
-
canonicalOfflinePrincipalId(attention.userId),
|
|
6119
|
-
attention.scopeId,
|
|
6120
|
-
attention.reason,
|
|
6121
|
-
attention.status === undefined ? null : attention.status,
|
|
6122
|
-
]);
|
|
6099
|
+
/** @deprecated Use {@link transactReplica} with `putPullAttentions`. */
|
|
6100
|
+
putPullAttention(attention) {
|
|
6101
|
+
return this.transactReplica({ putPullAttentions: [attention] });
|
|
6123
6102
|
}
|
|
6124
|
-
|
|
6125
|
-
|
|
6126
|
-
|
|
6127
|
-
scope.scopeId,
|
|
6128
|
-
]);
|
|
6103
|
+
/** @deprecated Use {@link transactReplica} with `removePullAttentions`. */
|
|
6104
|
+
removePullAttention(scope) {
|
|
6105
|
+
return this.transactReplica({ removePullAttentions: [scope] });
|
|
6129
6106
|
}
|
|
6130
6107
|
async clearUser(userId) {
|
|
6131
6108
|
await this.#transaction((database) => this.#clearUser(database, userId));
|
|
@@ -7212,7 +7189,16 @@ function assertSupportedOfflineMode(platform, mode) {
|
|
|
7212
7189
|
}
|
|
7213
7190
|
}
|
|
7214
7191
|
|
|
7215
|
-
/**
|
|
7192
|
+
/**
|
|
7193
|
+
* Experimental scoped local replica and outbox runtime for offline-capable Ionic applications.
|
|
7194
|
+
*
|
|
7195
|
+
* This entry point is not covered by the package's SemVer compatibility guarantee. Its public
|
|
7196
|
+
* APIs, persistence schema, and synchronization behavior may change incompatibly in a minor or
|
|
7197
|
+
* patch release before stabilization.
|
|
7198
|
+
*
|
|
7199
|
+
* @packageDocumentation
|
|
7200
|
+
* @experimental
|
|
7201
|
+
*/
|
|
7216
7202
|
|
|
7217
7203
|
/**
|
|
7218
7204
|
* Generated bundle index. Do not edit.
|