openchs-models 1.33.5 → 1.33.6
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 +20 -3
- package/package.json +1 -1
|
@@ -51,19 +51,36 @@ class RealmProxy {
|
|
|
51
51
|
*/
|
|
52
52
|
create(schemaName, object, updateMode = "never") {
|
|
53
53
|
const entityClass = this.entityMappingConfig.getEntityClass(schemaName);
|
|
54
|
-
const underlyingObject = (0, _RealmCollectionHelper.getUnderlyingRealmObject)(object);
|
|
55
54
|
const schema = entityClass.schema;
|
|
56
55
|
|
|
56
|
+
// Extract the underlying data from entity wrapper if needed
|
|
57
|
+
const rawObject = (0, _RealmCollectionHelper.getUnderlyingRealmObject)(object) || object;
|
|
58
|
+
|
|
57
59
|
// 🚀 FRAMEWORK-LEVEL: Automatically process embedded objects for Realm 12+ safety
|
|
58
|
-
const processedObject = _RealmEmbeddedObjectHandler.default.processEmbeddedObjects(
|
|
60
|
+
const processedObject = _RealmEmbeddedObjectHandler.default.processEmbeddedObjects(rawObject, schema);
|
|
59
61
|
const mandatoryObjectSchemaProperties = _lodash.default.keys(_lodash.default.pickBy(schema.properties, property => !property.optional));
|
|
60
62
|
const emptyMandatoryProperties = [];
|
|
61
63
|
const saveObjectKeys = Object.keys(processedObject);
|
|
62
64
|
if (updateMode === "never" || updateMode === false || _lodash.default.intersection(mandatoryObjectSchemaProperties, saveObjectKeys).length > 0) {
|
|
65
|
+
// Check for null/undefined mandatory properties that are present in the object
|
|
63
66
|
saveObjectKeys.forEach(x => {
|
|
64
67
|
const propertyValue = processedObject[x];
|
|
65
|
-
if (_lodash.default.isNil(propertyValue) && _lodash.default.some(mandatoryObjectSchemaProperties, y => y === x))
|
|
68
|
+
if (_lodash.default.isNil(propertyValue) && _lodash.default.some(mandatoryObjectSchemaProperties, y => y === x)) {
|
|
69
|
+
emptyMandatoryProperties.push(x);
|
|
70
|
+
}
|
|
66
71
|
});
|
|
72
|
+
|
|
73
|
+
// Enhanced validation: Only check for missing mandatory properties in strict update modes
|
|
74
|
+
// or when we have some mandatory properties present (indicating intent to save a complete entity)
|
|
75
|
+
const isStrictUpdateMode = updateMode === "never" || updateMode === false;
|
|
76
|
+
const hasSomeMandatoryProperties = _lodash.default.intersection(mandatoryObjectSchemaProperties, saveObjectKeys).length > 0;
|
|
77
|
+
if (isStrictUpdateMode && hasSomeMandatoryProperties) {
|
|
78
|
+
mandatoryObjectSchemaProperties.forEach(mandatoryProp => {
|
|
79
|
+
if (!saveObjectKeys.includes(mandatoryProp)) {
|
|
80
|
+
emptyMandatoryProperties.push(mandatoryProp);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
67
84
|
if (emptyMandatoryProperties.length > 0) {
|
|
68
85
|
throw new Error(`${emptyMandatoryProperties.join(",")} are mandatory for ${schemaName}, Keys being saved - ${saveObjectKeys}. UUID: ${processedObject.uuid}`);
|
|
69
86
|
}
|