You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
661 B
29 lines
661 B
4 years ago
|
'use strict';
|
||
|
|
||
|
const StrictModeError = require('../../error/strict');
|
||
|
|
||
|
module.exports = function handleImmutable(schematype, strict, obj, key, fullPath, ctx) {
|
||
|
if (schematype == null || !schematype.options || !schematype.options.immutable) {
|
||
|
return false;
|
||
|
}
|
||
|
let immutable = schematype.options.immutable;
|
||
|
|
||
|
if (typeof immutable === 'function') {
|
||
|
immutable = immutable.call(ctx, ctx);
|
||
|
}
|
||
|
if (!immutable) {
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
if (strict === false) {
|
||
|
return false;
|
||
|
}
|
||
|
if (strict === 'throw') {
|
||
|
throw new StrictModeError(null,
|
||
|
`Field ${fullPath} is immutable and strict = 'throw'`);
|
||
|
}
|
||
|
|
||
|
delete obj[key];
|
||
|
return true;
|
||
|
};
|