Skip to content

Commit

Permalink
Fix deepFreeze
Browse files Browse the repository at this point in the history
Actually deep freezing the `constrainedAbstractSqlModel`

Change-type: patch
Signed-off-by: Harald Fischer <[email protected]>
Signed-off-by: fisehara <[email protected]>
  • Loading branch information
fisehara committed May 4, 2023
1 parent c3a119f commit d285613
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/sbvr-api/permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -714,20 +714,20 @@ const onceGetter = <T, U extends keyof T>(
});
};

const deepFreezeExceptDefinition = (obj: AnyObject) => {
Object.freeze(obj);

const deepFreeze = (obj: AnyObject) => {
for (const prop of Object.getOwnPropertyNames(obj)) {
// We skip the definition because we know it's a property we've defined that will throw an error in some cases
const value = obj[prop];
if (
prop !== 'definition' &&
obj.hasOwnProperty(prop) &&
obj[prop] !== null &&
!['object', 'function'].includes(typeof obj[prop])
// `synonyms` is changed later on in the constrainedAbstractSqlModel.symbols get proxy
// `tables` is changed later on in the constrainedAbstractSqlModel.tables get proxy
!['synonyms', 'tables'].includes(prop) &&
value !== null &&
(typeof value === 'object' || typeof value === 'function')
) {
deepFreezeExceptDefinition(obj);
deepFreeze(value);
}
}
Object.freeze(obj);
};

const createBypassDefinition = (definition: Definition) =>
Expand Down Expand Up @@ -1095,7 +1095,7 @@ const getBoundConstrainedMemoizer = memoizeWeak(
},
},
);
deepFreezeExceptDefinition(constrainedAbstractSqlModel);
deepFreeze(constrainedAbstractSqlModel);
return constrainedAbstractSqlModel;
},
{
Expand Down

0 comments on commit d285613

Please sign in to comment.