| 3605 | */ |
| 3606 | |
| 3607 | function _checkImmutableSubpaths(subdoc, schematype, priorVal) { |
| 3608 | const schema = schematype.schema; |
| 3609 | if (schema == null) { |
| 3610 | return; |
| 3611 | } |
| 3612 | |
| 3613 | for (const key of Object.keys(schema.paths)) { |
| 3614 | const path = schema.paths[key]; |
| 3615 | if (path.$immutableSetter == null) { |
| 3616 | continue; |
| 3617 | } |
| 3618 | const oldVal = priorVal == null ? void 0 : priorVal.$__getValue(key); |
| 3619 | // Calling immutableSetter with `oldVal` even though it expects `newVal` |
| 3620 | // is intentional. That's because `$immutableSetter` compares its param |
| 3621 | // to the current value. |
| 3622 | path.$immutableSetter.call(subdoc, oldVal); |
| 3623 | } |
| 3624 | } |
| 3625 | |
| 3626 | /** |
| 3627 | * Saves this document by inserting a new document into the database if [document.isNew](https://mongoosejs.com/docs/api/document.html#Document.prototype.isNew()) is `true`, |