@rdlabo/ionic-angular-kit 21.4.3 → 21.4.5
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.
|
@@ -22,7 +22,8 @@ const RESERVED_COLUMN_NAMES = new Set([
|
|
|
22
22
|
* Begins a type-safe replica entity schema definition for the given select shape.
|
|
23
23
|
*
|
|
24
24
|
* Every key in `TSelect` must appear exactly once in `fields`, and column nullability
|
|
25
|
-
* must match the select property nullability.
|
|
25
|
+
* must match the select property nullability. An entity may map at most one field with
|
|
26
|
+
* {@link serverId}; omit it for local-only projections that have no remote row identity.
|
|
26
27
|
*/
|
|
27
28
|
function defineReplicaEntity() {
|
|
28
29
|
return function defineReplicaEntityConfig(definition) {
|
|
@@ -75,6 +76,13 @@ function nullable(column) {
|
|
|
75
76
|
function serverId() {
|
|
76
77
|
return { kind: 'serverId' };
|
|
77
78
|
}
|
|
79
|
+
/** Rejects a remote identity on a local-only projection before it reaches platform storage. */
|
|
80
|
+
function assertOfflineReplicaServerId(schema, value) {
|
|
81
|
+
const hasServerId = schema.fields.some((field) => field.policy === 'serverId');
|
|
82
|
+
if (!hasServerId && value !== null) {
|
|
83
|
+
throw new Error(`Offline replica source "${schema.sourceKey}" does not define a serverId field.`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
78
86
|
/** Excludes a source property from SQLite while retaining it in the select shape. */
|
|
79
87
|
function ignored(reason) {
|
|
80
88
|
return { kind: 'ignored', reason };
|
|
@@ -84,9 +92,9 @@ function buildOfflineReplicaEntitySchema(definition) {
|
|
|
84
92
|
validateIdentifier(definition.sourceKey, 'source key');
|
|
85
93
|
const sourceKeys = Object.keys(definition.fields).sort();
|
|
86
94
|
const serverIdCount = sourceKeys.filter((sourceKey) => definition.fields[sourceKey]?.kind === 'serverId').length;
|
|
87
|
-
if (serverIdCount
|
|
88
|
-
throw new Error('Replica entity must define
|
|
89
|
-
const hasServerId =
|
|
95
|
+
if (serverIdCount > 1)
|
|
96
|
+
throw new Error('Replica entity must define at most one serverId field.');
|
|
97
|
+
const hasServerId = serverIdCount === 1;
|
|
90
98
|
const fields = sourceKeys.map((sourceKey) => {
|
|
91
99
|
const fieldDef = definition.fields[sourceKey];
|
|
92
100
|
return materializeFieldDescriptor(sourceKey, fieldDef);
|
|
@@ -957,6 +965,7 @@ class IonicOfflineRepository {
|
|
|
957
965
|
}
|
|
958
966
|
#validateReplicaRow(row) {
|
|
959
967
|
const schema = this.#resolveReplicaEntitySchema(row.sourceKey);
|
|
968
|
+
assertOfflineReplicaServerId(schema, row.serverId);
|
|
960
969
|
encodeOfflineReplicaValues(schema, row.values);
|
|
961
970
|
if (row.confirmedValues !== null)
|
|
962
971
|
encodeOfflineReplicaValues(schema, row.confirmedValues);
|
|
@@ -2416,6 +2425,7 @@ class SqliteOfflineRepository {
|
|
|
2416
2425
|
}
|
|
2417
2426
|
#putReplicaRow(databaseId, row) {
|
|
2418
2427
|
const schema = this.#resolveReplicaEntitySchema(row.sourceKey);
|
|
2428
|
+
assertOfflineReplicaServerId(schema, row.serverId);
|
|
2419
2429
|
const encoded = encodeOfflineReplicaValues(schema, row.values);
|
|
2420
2430
|
const confirmedValues = row.confirmedValues === null ? null : projectOfflineReplicaValues(schema, row.confirmedValues);
|
|
2421
2431
|
const { sql, domainColumns } = this.#buildReplicaUpsertStatement(schema);
|
|
@@ -2637,5 +2647,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.17", ngImpo
|
|
|
2637
2647
|
* Generated bundle index. Do not edit.
|
|
2638
2648
|
*/
|
|
2639
2649
|
|
|
2640
|
-
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, OfflinePayloadValidationError, OfflineReplicaPullService, OfflineRequestFallbackService, OfflineRequestPolicyRegistry, OfflineSessionService, OfflineSyncService, SqliteOfflineRepository, booleanColumn, createCommunitySqliteDriver, datetime, decodeOfflineReplicaValues, defineOfflineReplicaSchema, defineReplicaEntity, encodeOfflineReplicaValues, ignored, integer, isOfflineFallbackError, json, nullable, offlineInterceptor, projectOfflineReplicaValues, provideOffline, provideOfflineRequestPolicy, real, selectOfflineRepository, serverId, sha256OfflineReplicaSchema, text };
|
|
2650
|
+
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, OfflinePayloadValidationError, OfflineReplicaPullService, OfflineRequestFallbackService, OfflineRequestPolicyRegistry, OfflineSessionService, OfflineSyncService, SqliteOfflineRepository, assertOfflineReplicaServerId, booleanColumn, createCommunitySqliteDriver, datetime, decodeOfflineReplicaValues, defineOfflineReplicaSchema, defineReplicaEntity, encodeOfflineReplicaValues, ignored, integer, isOfflineFallbackError, json, nullable, offlineInterceptor, projectOfflineReplicaValues, provideOffline, provideOfflineRequestPolicy, real, selectOfflineRepository, serverId, sha256OfflineReplicaSchema, text };
|
|
2641
2651
|
//# sourceMappingURL=rdlabo-ionic-angular-kit-offline.mjs.map
|