openchs-models 1.33.8 → 1.33.9
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/dist/framework/RealmProxy.js +21 -2
- package/package.json +1 -1
|
@@ -58,10 +58,29 @@ class RealmProxy {
|
|
|
58
58
|
const rawObject = (0, _RealmCollectionHelper.getUnderlyingRealmObject)(object) || object;
|
|
59
59
|
|
|
60
60
|
// 🚀 FRAMEWORK-LEVEL: Automatically process nested objects for Realm 12+ safety
|
|
61
|
-
// This is the only custom processing needed - Realm handles validation
|
|
62
61
|
const processedObject = _RealmNestedObjectHandler.default.processNestedObjects(rawObject, schema);
|
|
63
62
|
|
|
64
|
-
//
|
|
63
|
+
// Lightweight validation: Check for null/undefined mandatory properties
|
|
64
|
+
// This provides clear error messages for debugging production issues
|
|
65
|
+
// Validates when:
|
|
66
|
+
// 1. In strict creation mode ("never" or false), OR
|
|
67
|
+
// 2. Touching any mandatory property (prevents setting mandatory fields to null)
|
|
68
|
+
const mandatoryObjectSchemaProperties = this.entityMappingConfig.getMandatoryObjectSchemaProperties(schemaName);
|
|
69
|
+
const saveObjectKeys = Object.keys(processedObject);
|
|
70
|
+
if (updateMode === "never" || updateMode === false || _lodash.default.intersection(mandatoryObjectSchemaProperties, saveObjectKeys).length > 0) {
|
|
71
|
+
const emptyMandatoryProperties = [];
|
|
72
|
+
saveObjectKeys.forEach(key => {
|
|
73
|
+
const propertyValue = processedObject[key];
|
|
74
|
+
if (_lodash.default.isNil(propertyValue) && _lodash.default.some(mandatoryObjectSchemaProperties, mandatoryProp => mandatoryProp === key)) {
|
|
75
|
+
emptyMandatoryProperties.push(key);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
if (emptyMandatoryProperties.length > 0) {
|
|
79
|
+
throw new Error(`${emptyMandatoryProperties.join(",")} are mandatory for ${schemaName}, ` + `Keys being saved - ${saveObjectKeys.join(",")}. UUID: ${processedObject.uuid}`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Let Realm handle remaining validation (types, constraints, etc.)
|
|
65
84
|
const dbEntity = this.realmDb.create(schemaName, processedObject, updateMode);
|
|
66
85
|
return new entityClass(dbEntity);
|
|
67
86
|
}
|