1 | 'use strict';
|
2 |
|
3 | const StrictModeError = require('../../error/strict');
|
4 |
|
5 | module.exports = function handleImmutable(schematype, strict, obj, key, fullPath, ctx) {
|
6 | if (schematype == null || !schematype.options || !schematype.options.immutable) {
|
7 | return false;
|
8 | }
|
9 | let immutable = schematype.options.immutable;
|
10 |
|
11 | if (typeof immutable === 'function') {
|
12 | immutable = immutable.call(ctx, ctx);
|
13 | }
|
14 | if (!immutable) {
|
15 | return false;
|
16 | }
|
17 |
|
18 | if (strict === false) {
|
19 | return false;
|
20 | }
|
21 | if (strict === 'throw') {
|
22 | throw new StrictModeError(null,
|
23 | `Field ${fullPath} is immutable and strict = 'throw'`);
|
24 | }
|
25 |
|
26 | delete obj[key];
|
27 | return true;
|
28 | };
|