@rdlabo/ionic-angular-kit 21.5.29 → 21.5.31
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.
|
@@ -852,6 +852,8 @@ function normalizeOfflineReplicaPullPage(page) {
|
|
|
852
852
|
}
|
|
853
853
|
/** DI token for the application-provided explicit replica pull transport. */
|
|
854
854
|
const OFFLINE_REPLICA_PULLER = new InjectionToken('OFFLINE_REPLICA_PULLER');
|
|
855
|
+
/** Optional product adapter for local-only replica projections. */
|
|
856
|
+
const OFFLINE_REPLICA_PROJECTOR = new InjectionToken('OFFLINE_REPLICA_PROJECTOR');
|
|
855
857
|
|
|
856
858
|
/** DI token for product-independent offline persistence settings. */
|
|
857
859
|
const OFFLINE_KIT_OPTIONS = new InjectionToken('OFFLINE_KIT_OPTIONS');
|
|
@@ -900,6 +902,11 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.17", ngImpo
|
|
|
900
902
|
|
|
901
903
|
/** Current durable storage schema used by both web and native repositories. */
|
|
902
904
|
const OFFLINE_SCHEMA_VERSION = 1;
|
|
905
|
+
/** Canonical physical key shared by every repository and replica transaction coordinator. */
|
|
906
|
+
function canonicalOfflineReplicaRowKey(schema, row) {
|
|
907
|
+
const partition = schema.scope === 'user' ? 'user' : String(row.scopeId);
|
|
908
|
+
return `${canonicalOfflinePrincipalId(row.userId)}:${partition}:${row.sourceKey}:${canonicalOfflineReplicaIdentity(row.identity)}`;
|
|
909
|
+
}
|
|
903
910
|
/** DI token for the selected platform repository. */
|
|
904
911
|
const OFFLINE_REPOSITORY = new InjectionToken('OFFLINE_REPOSITORY');
|
|
905
912
|
/** Selects encrypted SQLite on native platforms and Ionic Storage on web. */
|
|
@@ -1422,8 +1429,7 @@ class IonicOfflineRepository {
|
|
|
1422
1429
|
}
|
|
1423
1430
|
#rowKey(row) {
|
|
1424
1431
|
const schema = this.#resolveReplicaEntitySchema(row.sourceKey);
|
|
1425
|
-
|
|
1426
|
-
return `${canonicalOfflinePrincipalId(row.userId)}:${partition}:${row.sourceKey}:${canonicalOfflineReplicaIdentity(row.identity)}`;
|
|
1432
|
+
return canonicalOfflineReplicaRowKey(schema, row);
|
|
1427
1433
|
}
|
|
1428
1434
|
#findRowByAddress(rows, scope, sourceKey, schema, identity) {
|
|
1429
1435
|
return Object.values(rows).find((row) => {
|
|
@@ -1613,6 +1619,7 @@ class OfflineReplicaPullService {
|
|
|
1613
1619
|
#repository = inject(OFFLINE_REPOSITORY);
|
|
1614
1620
|
#options = inject(OFFLINE_KIT_OPTIONS);
|
|
1615
1621
|
#puller = inject(OFFLINE_REPLICA_PULLER);
|
|
1622
|
+
#projector = inject(OFFLINE_REPLICA_PROJECTOR, { optional: true });
|
|
1616
1623
|
#executor = inject(OFFLINE_COMMAND_EXECUTOR);
|
|
1617
1624
|
#replicaMutations = inject(OfflineReplicaMutationCoordinator);
|
|
1618
1625
|
#schemaHash = null;
|
|
@@ -1620,33 +1627,48 @@ class OfflineReplicaPullService {
|
|
|
1620
1627
|
if (this.#options.mode === 'readCacheOnly')
|
|
1621
1628
|
return;
|
|
1622
1629
|
const schemaHash = await (this.#schemaHash ??= sha256OfflineReplicaSchema(this.#options.replicaSchema));
|
|
1623
|
-
let
|
|
1630
|
+
let persistedCursor = (await this.#repository.getReplicaCursor(scope))?.cursor ?? '';
|
|
1631
|
+
let requestCursor = persistedCursor;
|
|
1632
|
+
let rebaselinePending = false;
|
|
1624
1633
|
for (;;) {
|
|
1625
1634
|
const page = await this.#puller.pull({
|
|
1626
1635
|
scope,
|
|
1627
|
-
cursor,
|
|
1636
|
+
cursor: requestCursor,
|
|
1628
1637
|
schemaVersion: this.#options.replicaSchema.version,
|
|
1629
1638
|
schemaHash,
|
|
1630
1639
|
});
|
|
1631
1640
|
this.#assertPullPage(page);
|
|
1632
1641
|
this.#assertHandshake(page.schemaVersion, page.schemaHash, schemaHash);
|
|
1633
|
-
if (page.hasMore && page.nextCursor ===
|
|
1642
|
+
if (page.hasMore && page.nextCursor === requestCursor) {
|
|
1634
1643
|
throw new Error(`Offline replica pull cursor did not advance for scope ${scope.userId}:${scope.scopeId}.`);
|
|
1635
1644
|
}
|
|
1636
|
-
if (page.changes.length === 0 && !page.hasMore && page.nextCursor ===
|
|
1645
|
+
if (page.changes.length === 0 && !page.hasMore && page.nextCursor === requestCursor && !rebaselinePending) {
|
|
1637
1646
|
return;
|
|
1638
1647
|
}
|
|
1648
|
+
if (page.rebaselineRequired && page.changes.length === 0 && !page.hasMore) {
|
|
1649
|
+
throw new Error('Offline replica rebaseline marker must lead to a snapshot page.');
|
|
1650
|
+
}
|
|
1651
|
+
if (page.rebaselineRequired && page.changes.length === 0 && page.hasMore) {
|
|
1652
|
+
rebaselinePending = true;
|
|
1653
|
+
requestCursor = page.nextCursor;
|
|
1654
|
+
continue;
|
|
1655
|
+
}
|
|
1639
1656
|
const applied = await this.#replicaMutations.run(async () => {
|
|
1640
1657
|
const currentCursor = (await this.#repository.getReplicaCursor(scope))?.cursor ?? '';
|
|
1641
|
-
if (currentCursor !==
|
|
1658
|
+
if (currentCursor !== persistedCursor)
|
|
1642
1659
|
return currentCursor;
|
|
1643
1660
|
const scopeCommands = await this.#repository.getCommands(scope);
|
|
1644
1661
|
const userCommands = this.#repository.getCommandsForUser ? await this.#repository.getCommandsForUser(scope.userId) : scopeCommands;
|
|
1645
1662
|
const changes = this.#collapseChanges(page.changes);
|
|
1646
1663
|
const putRows = [];
|
|
1647
1664
|
const removeRows = [];
|
|
1665
|
+
const rebasedPutRows = [];
|
|
1666
|
+
const rebasedRemoveRows = [];
|
|
1648
1667
|
const putCommands = new Map();
|
|
1649
1668
|
const removeCommandIds = new Set();
|
|
1669
|
+
if (rebaselinePending || page.rebaselineRequired) {
|
|
1670
|
+
removeRows.push(...(await this.#confirmedRowsForRebaseline(scope, userCommands)));
|
|
1671
|
+
}
|
|
1650
1672
|
for (const change of changes) {
|
|
1651
1673
|
const schema = this.#entitySchema(change.sourceKey);
|
|
1652
1674
|
const commands = schema.scope === 'user' ? userCommands : scopeCommands;
|
|
@@ -1730,10 +1752,29 @@ class OfflineReplicaPullService {
|
|
|
1730
1752
|
});
|
|
1731
1753
|
continue;
|
|
1732
1754
|
}
|
|
1733
|
-
const
|
|
1755
|
+
const revisionChanged = related.some((command) => command.baseRevision !== change.serverRevision);
|
|
1756
|
+
const rebaseEligible = related.every((command) => (command.state === 'pending' || command.state === 'retry_wait') && command.serverCommitUnknown !== true);
|
|
1757
|
+
const rebase = revisionChanged && rebaseEligible
|
|
1758
|
+
? ((await this.#executor.rebasePendingCommands?.(related, confirmedValues, change.serverRevision, await this.#currentCompanionRows(related))) ?? null)
|
|
1759
|
+
: null;
|
|
1760
|
+
this.#assertRebasedSteps(related, rebase?.steps ?? null);
|
|
1761
|
+
const conflicted = revisionChanged && rebase === null;
|
|
1762
|
+
const rebasedCommands = rebase
|
|
1763
|
+
? related.map((command, index) => ({
|
|
1764
|
+
...command,
|
|
1765
|
+
baseRevision: change.serverRevision,
|
|
1766
|
+
optimisticValue: rebase.steps[index].optimisticValue,
|
|
1767
|
+
...(rebase.steps[index].optimisticCompanions === undefined
|
|
1768
|
+
? {}
|
|
1769
|
+
: { optimisticCompanions: rebase.steps[index].optimisticCompanions }),
|
|
1770
|
+
}))
|
|
1771
|
+
: [];
|
|
1772
|
+
for (const command of rebasedCommands)
|
|
1773
|
+
putCommands.set(command.commandId, command);
|
|
1774
|
+
this.#appendRebasedCompanionRows(rebasedCommands, rebasedPutRows, rebasedRemoveRows);
|
|
1734
1775
|
putRows.push({
|
|
1735
1776
|
...existing,
|
|
1736
|
-
values: hasPending ? existing.values : confirmedValues,
|
|
1777
|
+
values: rebasedCommands.at(-1)?.optimisticValue ?? (hasPending ? existing.values : confirmedValues),
|
|
1737
1778
|
confirmedValues,
|
|
1738
1779
|
serverRevision: change.serverRevision,
|
|
1739
1780
|
fetchedAt: Date.now(),
|
|
@@ -1750,9 +1791,21 @@ class OfflineReplicaPullService {
|
|
|
1750
1791
|
}
|
|
1751
1792
|
}
|
|
1752
1793
|
}
|
|
1794
|
+
const projection = await this.#projector?.project({
|
|
1795
|
+
scope,
|
|
1796
|
+
changes,
|
|
1797
|
+
commands: scopeCommands,
|
|
1798
|
+
repository: this.#repository,
|
|
1799
|
+
});
|
|
1800
|
+
this.#assertProjection(scope, projection);
|
|
1801
|
+
const finalRows = this.#mergeRowMutations([
|
|
1802
|
+
{ putRows, removeRows },
|
|
1803
|
+
{ putRows: projection?.putRows ?? [], removeRows: projection?.removeRows ?? [] },
|
|
1804
|
+
{ putRows: rebasedPutRows, removeRows: rebasedRemoveRows },
|
|
1805
|
+
]);
|
|
1753
1806
|
await this.#repository.transactReplica({
|
|
1754
|
-
putRows,
|
|
1755
|
-
removeRows,
|
|
1807
|
+
putRows: finalRows.putRows,
|
|
1808
|
+
removeRows: finalRows.removeRows,
|
|
1756
1809
|
putCommands: [...putCommands.values()],
|
|
1757
1810
|
removeCommandIds: [...removeCommandIds],
|
|
1758
1811
|
putCursors: [{ ...scope, cursor: page.nextCursor }],
|
|
@@ -1760,14 +1813,55 @@ class OfflineReplicaPullService {
|
|
|
1760
1813
|
return page.nextCursor;
|
|
1761
1814
|
});
|
|
1762
1815
|
if (applied !== page.nextCursor) {
|
|
1763
|
-
|
|
1816
|
+
persistedCursor = applied;
|
|
1817
|
+
requestCursor = applied;
|
|
1818
|
+
rebaselinePending = false;
|
|
1764
1819
|
continue;
|
|
1765
1820
|
}
|
|
1766
|
-
|
|
1821
|
+
persistedCursor = page.nextCursor;
|
|
1822
|
+
requestCursor = page.nextCursor;
|
|
1823
|
+
rebaselinePending = false;
|
|
1767
1824
|
if (!page.hasMore)
|
|
1768
1825
|
return;
|
|
1769
1826
|
}
|
|
1770
1827
|
}
|
|
1828
|
+
async #confirmedRowsForRebaseline(scope, commands) {
|
|
1829
|
+
const preserved = new Set(commands.flatMap((command) => (command.optimisticCompanions ?? []).map((companion) => this.#rowKey(companion.key))));
|
|
1830
|
+
const rows = (await Promise.all(this.#options.replicaSchema.entities.map((entity) => this.#repository.getReplicaRows(scope, entity.sourceKey)))).flat();
|
|
1831
|
+
return rows.filter((row) => row.syncState === 'confirmed' && !preserved.has(this.#rowKey(row)));
|
|
1832
|
+
}
|
|
1833
|
+
#rowKey(row) {
|
|
1834
|
+
return canonicalOfflineReplicaRowKey(this.#entitySchema(row.sourceKey), row);
|
|
1835
|
+
}
|
|
1836
|
+
#mergeRowMutations(layers) {
|
|
1837
|
+
const mutations = new Map();
|
|
1838
|
+
for (const layer of layers) {
|
|
1839
|
+
for (const row of layer.removeRows)
|
|
1840
|
+
mutations.set(this.#rowKey(row), { kind: 'remove', row });
|
|
1841
|
+
for (const row of layer.putRows)
|
|
1842
|
+
mutations.set(this.#rowKey(row), { kind: 'put', row });
|
|
1843
|
+
}
|
|
1844
|
+
const putRows = [];
|
|
1845
|
+
const removeRows = [];
|
|
1846
|
+
for (const mutation of mutations.values()) {
|
|
1847
|
+
if (mutation.kind === 'put')
|
|
1848
|
+
putRows.push(mutation.row);
|
|
1849
|
+
else
|
|
1850
|
+
removeRows.push(mutation.row);
|
|
1851
|
+
}
|
|
1852
|
+
return { putRows, removeRows };
|
|
1853
|
+
}
|
|
1854
|
+
#assertProjection(scope, projection) {
|
|
1855
|
+
for (const row of [...(projection?.putRows ?? []), ...(projection?.removeRows ?? [])]) {
|
|
1856
|
+
const schema = this.#entitySchema(row.sourceKey);
|
|
1857
|
+
if (schema.identity.kind !== 'localOnly') {
|
|
1858
|
+
throw new Error(`Offline replica projector may only mutate localOnly source "${row.sourceKey}".`);
|
|
1859
|
+
}
|
|
1860
|
+
if (row.userId !== scope.userId || row.scopeId !== scope.scopeId || row.identity.kind !== 'local') {
|
|
1861
|
+
throw new Error('Offline replica projector rows must use the current scope and local identity.');
|
|
1862
|
+
}
|
|
1863
|
+
}
|
|
1864
|
+
}
|
|
1771
1865
|
#assertPullPage(page) {
|
|
1772
1866
|
if (typeof page.nextCursor !== 'string') {
|
|
1773
1867
|
throw new Error('Offline replica pull page nextCursor must be a string.');
|
|
@@ -1778,10 +1872,50 @@ class OfflineReplicaPullService {
|
|
|
1778
1872
|
if (!Array.isArray(page.changes)) {
|
|
1779
1873
|
throw new Error('Offline replica pull page changes must be an array.');
|
|
1780
1874
|
}
|
|
1875
|
+
if (page.rebaselineRequired !== undefined && typeof page.rebaselineRequired !== 'boolean') {
|
|
1876
|
+
throw new Error('Offline replica pull page rebaselineRequired must be a boolean when present.');
|
|
1877
|
+
}
|
|
1781
1878
|
for (const [index, change] of page.changes.entries()) {
|
|
1782
1879
|
this.#assertPullChange(change, index);
|
|
1783
1880
|
}
|
|
1784
1881
|
}
|
|
1882
|
+
#assertRebasedSteps(original, steps) {
|
|
1883
|
+
if (steps === null)
|
|
1884
|
+
return;
|
|
1885
|
+
if (steps.length !== original.length) {
|
|
1886
|
+
throw new Error('Rebased offline values must match the aggregate command count.');
|
|
1887
|
+
}
|
|
1888
|
+
for (const [index, step] of steps.entries()) {
|
|
1889
|
+
const originalKeys = (original[index]?.optimisticCompanions ?? []).map((item) => this.#rowKey(item.key)).sort();
|
|
1890
|
+
const rebasedKeys = (step.optimisticCompanions ?? []).map((item) => this.#rowKey(item.key)).sort();
|
|
1891
|
+
if (JSON.stringify(originalKeys) !== JSON.stringify(rebasedKeys)) {
|
|
1892
|
+
throw new Error('Rebased offline companions must preserve each command footprint.');
|
|
1893
|
+
}
|
|
1894
|
+
}
|
|
1895
|
+
}
|
|
1896
|
+
#appendRebasedCompanionRows(commands, putRows, removeRows) {
|
|
1897
|
+
const latest = new Map();
|
|
1898
|
+
for (const command of commands) {
|
|
1899
|
+
for (const companion of command.optimisticCompanions ?? []) {
|
|
1900
|
+
latest.set(this.#rowKey(companion.key), { key: companion.key, after: companion.after });
|
|
1901
|
+
}
|
|
1902
|
+
}
|
|
1903
|
+
for (const { key, after } of latest.values()) {
|
|
1904
|
+
if (after)
|
|
1905
|
+
putRows.push(after);
|
|
1906
|
+
else
|
|
1907
|
+
removeRows.push(key);
|
|
1908
|
+
}
|
|
1909
|
+
}
|
|
1910
|
+
async #currentCompanionRows(commands) {
|
|
1911
|
+
const keys = new Map(commands.flatMap((command) => (command.optimisticCompanions ?? []).map((companion) => [this.#rowKey(companion.key), companion.key])));
|
|
1912
|
+
const rows = await Promise.all([...keys.values()].map((key) => {
|
|
1913
|
+
const companionScope = { userId: key.userId, scopeId: key.scopeId };
|
|
1914
|
+
return (this.#repository.getReplicaRowIncludingPendingDelete?.(companionScope, key.sourceKey, key.identity) ??
|
|
1915
|
+
this.#repository.getReplicaRow(companionScope, key.sourceKey, key.identity));
|
|
1916
|
+
}));
|
|
1917
|
+
return rows.filter((row) => row !== null);
|
|
1918
|
+
}
|
|
1785
1919
|
#assertPullChange(change, index) {
|
|
1786
1920
|
const label = `Offline replica pull page changes[${index}]`;
|
|
1787
1921
|
if (!isPlainObject(change)) {
|
|
@@ -2449,7 +2583,10 @@ class OfflineSyncService {
|
|
|
2449
2583
|
const session = await this.#beginEnqueueSession(generation);
|
|
2450
2584
|
this.#assertEnqueueScope(session, request.scopeId);
|
|
2451
2585
|
const materialization = await this.#materializeEnqueue(session.userId, request, replicaTransaction, replaced);
|
|
2452
|
-
await this.#
|
|
2586
|
+
const currentCommands = await this.#commandsForUser(session.userId);
|
|
2587
|
+
const retainedCommands = replaced ? currentCommands.filter((command) => command.commandId !== replaced.commandId) : currentCommands;
|
|
2588
|
+
this.#assertDistinctBatchFootprints([materialization], retainedCommands);
|
|
2589
|
+
await this.#assertOutboxCapacity(session.userId, [materialization.command], replaced?.commandId, currentCommands);
|
|
2453
2590
|
await this.#commitMaterializedEnqueues([materialization], generation, options, replaced ? [replaced.commandId] : undefined);
|
|
2454
2591
|
return materialization.command.commandId;
|
|
2455
2592
|
}
|
|
@@ -2458,13 +2595,18 @@ class OfflineSyncService {
|
|
|
2458
2595
|
throw new Error('Prepared offline batch must contain at least one command.');
|
|
2459
2596
|
}
|
|
2460
2597
|
const session = await this.#beginEnqueueSession(generation);
|
|
2598
|
+
const currentCommands = await this.#commandsForUser(session.userId);
|
|
2599
|
+
this.#rememberCreatedAt(currentCommands);
|
|
2600
|
+
const firstCreatedAt = Math.max(Date.now(), this.#lastCommandCreatedAt + 1);
|
|
2601
|
+
this.#lastCommandCreatedAt = firstCreatedAt + prepared.length - 1;
|
|
2461
2602
|
const materializations = [];
|
|
2462
|
-
for (const entry of prepared) {
|
|
2603
|
+
for (const [index, entry] of prepared.entries()) {
|
|
2463
2604
|
this.#assertEnqueueScope(session, entry.request.scopeId);
|
|
2464
|
-
materializations.push(await this.#materializeEnqueue(session.userId, entry.request, entry.replicaTransaction));
|
|
2605
|
+
materializations.push(await this.#materializeEnqueue(session.userId, entry.request, entry.replicaTransaction, undefined, firstCreatedAt + index));
|
|
2465
2606
|
}
|
|
2466
|
-
this.#assertDistinctBatchFootprints(materializations);
|
|
2467
|
-
await this.#assertOutboxCapacity(session.userId, materializations.map((item) => item.command));
|
|
2607
|
+
this.#assertDistinctBatchFootprints(materializations, currentCommands);
|
|
2608
|
+
await this.#assertOutboxCapacity(session.userId, materializations.map((item) => item.command), undefined, currentCommands);
|
|
2609
|
+
options.assertCurrent?.();
|
|
2468
2610
|
await this.#commitMaterializedEnqueues(materializations, generation, options);
|
|
2469
2611
|
return materializations.map((item) => item.command.commandId);
|
|
2470
2612
|
}
|
|
@@ -2489,7 +2631,7 @@ class OfflineSyncService {
|
|
|
2489
2631
|
}
|
|
2490
2632
|
this.noteScope({ userId: session.userId, scopeId });
|
|
2491
2633
|
}
|
|
2492
|
-
async #materializeEnqueue(userId, request, replicaTransaction, replaced) {
|
|
2634
|
+
async #materializeEnqueue(userId, request, replicaTransaction, replaced, createdAt) {
|
|
2493
2635
|
const scope = { userId, scopeId: request.scopeId };
|
|
2494
2636
|
this.noteScope(scope);
|
|
2495
2637
|
const commandIdentity = offlineCommandLookupIdentity(request.identity);
|
|
@@ -2512,7 +2654,7 @@ class OfflineSyncService {
|
|
|
2512
2654
|
state: 'pending',
|
|
2513
2655
|
attempts: 0,
|
|
2514
2656
|
retryAt: null,
|
|
2515
|
-
createdAt: replaced?.createdAt ?? (await this.#nextCommandCreatedAt(userId)),
|
|
2657
|
+
createdAt: replaced?.createdAt ?? createdAt ?? (await this.#nextCommandCreatedAt(userId)),
|
|
2516
2658
|
lastErrorCode: null,
|
|
2517
2659
|
};
|
|
2518
2660
|
if (replaced &&
|
|
@@ -2594,9 +2736,15 @@ class OfflineSyncService {
|
|
|
2594
2736
|
command = { ...command, optimisticCompanions };
|
|
2595
2737
|
return { command, optimisticRow, optimisticCompanions };
|
|
2596
2738
|
}
|
|
2597
|
-
#assertDistinctBatchFootprints(entries) {
|
|
2739
|
+
#assertDistinctBatchFootprints(entries, existingCommands) {
|
|
2598
2740
|
const aggregates = new Set();
|
|
2599
2741
|
const replicaKeys = new Set();
|
|
2742
|
+
const existingFootprints = new Map();
|
|
2743
|
+
for (const command of existingCommands) {
|
|
2744
|
+
const aggregate = this.#aggregateKey(command);
|
|
2745
|
+
for (const key of this.#commandFootprintKeys(command))
|
|
2746
|
+
existingFootprints.set(key, aggregate);
|
|
2747
|
+
}
|
|
2600
2748
|
for (const entry of entries) {
|
|
2601
2749
|
const aggregate = this.#aggregateKey(entry.command);
|
|
2602
2750
|
if (aggregates.has(aggregate)) {
|
|
@@ -2610,10 +2758,23 @@ class OfflineSyncService {
|
|
|
2610
2758
|
if (replicaKeys.has(key)) {
|
|
2611
2759
|
throw new Error('Prepared offline batch contains overlapping replica footprints.');
|
|
2612
2760
|
}
|
|
2761
|
+
const existingAggregate = existingFootprints.get(key);
|
|
2762
|
+
if (existingAggregate !== undefined && existingAggregate !== aggregate) {
|
|
2763
|
+
throw new Error('Offline commands for different aggregates cannot share a replica footprint.');
|
|
2764
|
+
}
|
|
2613
2765
|
replicaKeys.add(key);
|
|
2614
2766
|
}
|
|
2615
2767
|
}
|
|
2616
2768
|
}
|
|
2769
|
+
#commandFootprintKeys(command) {
|
|
2770
|
+
const identity = command.identity.kind === 'generated'
|
|
2771
|
+
? offlineGeneratedReplicaIdentity(command.identity.localId, null)
|
|
2772
|
+
: { kind: 'natural', naturalKey: command.identity.naturalKey };
|
|
2773
|
+
return [
|
|
2774
|
+
this.#replicaRowKey({ ...command, identity }),
|
|
2775
|
+
...(command.optimisticCompanions ?? []).map((companion) => this.#replicaRowKey(companion.key)),
|
|
2776
|
+
];
|
|
2777
|
+
}
|
|
2617
2778
|
async #commitMaterializedEnqueues(entries, generation, options, removeCommandIds) {
|
|
2618
2779
|
if (generation !== this.#generation) {
|
|
2619
2780
|
throw new Error('Offline session changed before the command could be persisted');
|
|
@@ -2711,12 +2872,10 @@ class OfflineSyncService {
|
|
|
2711
2872
|
};
|
|
2712
2873
|
}
|
|
2713
2874
|
#replicaRowKey(key) {
|
|
2714
|
-
return
|
|
2875
|
+
return canonicalOfflineReplicaRowKey(this.#entitySchema(key.sourceKey), key);
|
|
2715
2876
|
}
|
|
2716
|
-
async #assertOutboxCapacity(userId, newCommands, excludingCommandId) {
|
|
2717
|
-
const currentCommands = this.#
|
|
2718
|
-
? await this.#repository.getCommandsForUser(userId)
|
|
2719
|
-
: (await Promise.all([...this.#knownScopes.values()].filter((scope) => scope.userId === userId).map((scope) => this.#repository.getCommands(scope)))).flat();
|
|
2877
|
+
async #assertOutboxCapacity(userId, newCommands, excludingCommandId, knownCommands) {
|
|
2878
|
+
const currentCommands = knownCommands ?? (await this.#commandsForUser(userId));
|
|
2720
2879
|
const commands = excludingCommandId
|
|
2721
2880
|
? currentCommands.filter((candidate) => candidate.commandId !== excludingCommandId)
|
|
2722
2881
|
: currentCommands;
|
|
@@ -2731,6 +2890,11 @@ class OfflineSyncService {
|
|
|
2731
2890
|
throw new OfflineOutboxCapacityError('serialized_bytes', commands.length, currentBytes);
|
|
2732
2891
|
}
|
|
2733
2892
|
}
|
|
2893
|
+
async #commandsForUser(userId) {
|
|
2894
|
+
return this.#repository.getCommandsForUser
|
|
2895
|
+
? this.#repository.getCommandsForUser(userId)
|
|
2896
|
+
: (await Promise.all([...this.#knownScopes.values()].filter((scope) => scope.userId === userId).map((scope) => this.#repository.getCommands(scope)))).flat();
|
|
2897
|
+
}
|
|
2734
2898
|
#serializedOutboxBytes(commands) {
|
|
2735
2899
|
return new TextEncoder().encode(JSON.stringify(commands)).byteLength;
|
|
2736
2900
|
}
|
|
@@ -3415,9 +3579,7 @@ class OfflineSyncService {
|
|
|
3415
3579
|
return commands;
|
|
3416
3580
|
}
|
|
3417
3581
|
async #nextCommandCreatedAt(userId) {
|
|
3418
|
-
const commands = this.#
|
|
3419
|
-
? await this.#repository.getCommandsForUser(userId)
|
|
3420
|
-
: await this.#readKnownCommands();
|
|
3582
|
+
const commands = await this.#commandsForUser(userId);
|
|
3421
3583
|
this.#rememberCreatedAt(commands);
|
|
3422
3584
|
const createdAt = Math.max(Date.now(), this.#lastCommandCreatedAt + 1);
|
|
3423
3585
|
this.#lastCommandCreatedAt = createdAt;
|
|
@@ -4635,7 +4797,7 @@ class SqliteOfflineRepository {
|
|
|
4635
4797
|
}
|
|
4636
4798
|
#replicaRowKey(row) {
|
|
4637
4799
|
const schema = this.#resolveReplicaEntitySchema(row.sourceKey);
|
|
4638
|
-
return
|
|
4800
|
+
return canonicalOfflineReplicaRowKey(schema, row);
|
|
4639
4801
|
}
|
|
4640
4802
|
#assertReplicaIdentityAssignment(schema, existing, incoming, release) {
|
|
4641
4803
|
if (release && schema.identity.kind !== 'generated') {
|
|
@@ -4788,6 +4950,9 @@ function provideOffline(options) {
|
|
|
4788
4950
|
? { provide: OFFLINE_REPLICA_PULLER, useExisting: options.replicaPuller }
|
|
4789
4951
|
: { provide: OFFLINE_REPLICA_PULLER, useValue: READ_CACHE_ONLY_REPLICA_PULLER },
|
|
4790
4952
|
...(options.commandHooks ? [options.commandHooks, { provide: OFFLINE_COMMAND_HOOKS, useExisting: options.commandHooks }] : []),
|
|
4953
|
+
...(options.replicaProjector
|
|
4954
|
+
? [options.replicaProjector, { provide: OFFLINE_REPLICA_PROJECTOR, useExisting: options.replicaProjector }]
|
|
4955
|
+
: []),
|
|
4791
4956
|
...options.requestPolicies.flatMap((policy) => provideOfflineRequestPolicy(policy)),
|
|
4792
4957
|
...(options.mutationPolicies ?? []).flatMap((policy) => provideOfflineMutationRequestPolicy(policy)),
|
|
4793
4958
|
...(options.providers ?? []),
|
|
@@ -4915,5 +5080,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.17", ngImpo
|
|
|
4915
5080
|
* Generated bundle index. Do not edit.
|
|
4916
5081
|
*/
|
|
4917
5082
|
|
|
4918
|
-
export { COMMUNITY_SQLITE, DEFAULT_OFFLINE_COMMAND_HOOKS, IonicOfflineRepository, OFFLINE_BYPASS, OFFLINE_COMMAND_EXECUTOR, OFFLINE_COMMAND_HOOKS, OFFLINE_KIT_OPTIONS, OFFLINE_MUTATION_REQUEST_POLICIES, OFFLINE_REPLICA_PULLER, OFFLINE_REPOSITORY, OFFLINE_REQUEST_POLICIES, OFFLINE_RESPONSE_HEADER, OFFLINE_SCHEMA_VERSION, OFFLINE_SYNC_CONTEXT, OfflineCommandInFlightError, OfflineCoordinatorService, OfflineMutationPolicyConflictError, OfflineMutationProtocolError, OfflineMutationRequestPolicyRegistry, OfflineNetworkService, OfflineOutboxCapacityError, OfflinePayloadValidationError, OfflineReplicaMutationCoordinator, 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, parseOfflineMutationEnvelope, parseOfflinePrincipalId, projectOfflineReplicaValues, provideOffline, provideOfflineMutationRequestPolicy, provideOfflineRequestPolicy, real, replicaAddressFromIdentity, requirePositiveOfflineInteger, selectOfflineRepository, serializeOfflineCommandIdentity, sha256OfflineReplicaSchema, text };
|
|
5083
|
+
export { COMMUNITY_SQLITE, DEFAULT_OFFLINE_COMMAND_HOOKS, IonicOfflineRepository, 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_SCHEMA_VERSION, OFFLINE_SYNC_CONTEXT, OfflineCommandInFlightError, OfflineCoordinatorService, OfflineMutationPolicyConflictError, OfflineMutationProtocolError, OfflineMutationRequestPolicyRegistry, OfflineNetworkService, OfflineOutboxCapacityError, OfflinePayloadValidationError, OfflineReplicaMutationCoordinator, OfflineReplicaPullService, OfflineRequestFallbackService, OfflineRequestPolicyRegistry, OfflineSessionService, OfflineSyncService, SqliteOfflineRepository, assertOfflineLocalId, assertOfflineReplicaGeneratedRemoteId, assertOfflineReplicaNaturalKeyBaseline, booleanColumn, canonicalOfflineCommandIdentity, canonicalOfflinePrincipalId, canonicalOfflineRemoteIdentity, canonicalOfflineReplicaIdentity, canonicalOfflineReplicaRowKey, 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, parseOfflineMutationEnvelope, parseOfflinePrincipalId, projectOfflineReplicaValues, provideOffline, provideOfflineMutationRequestPolicy, provideOfflineRequestPolicy, real, replicaAddressFromIdentity, requirePositiveOfflineInteger, selectOfflineRepository, serializeOfflineCommandIdentity, sha256OfflineReplicaSchema, text };
|
|
4919
5084
|
//# sourceMappingURL=rdlabo-ionic-angular-kit-offline.mjs.map
|