Uname: Linux business55.web-hosting.com 4.18.0-553.lve.el8.x86_64 #1 SMP Mon May 27 15:27:34 UTC 2024 x86_64
Software: LiteSpeed
PHP version: 8.1.31 [ PHP INFO ] PHP os: Linux
Server Ip: 162.213.251.212
Your Ip: 3.138.181.93
User: allssztx (535) | Group: allssztx (533)
Safe Mode: OFF
Disable Function:
NONE

name : moveImmutableProperties.js
'use strict';

const get = require('../get');

/**
 * Given an update, move all $set on immutable properties to $setOnInsert.
 * This should only be called for upserts, because $setOnInsert bypasses the
 * strictness check for immutable properties.
 */

module.exports = function moveImmutableProperties(schema, update, ctx) {
  if (update == null) {
    return;
  }

  const keys = Object.keys(update);
  for (const key of keys) {
    const isDollarKey = key.startsWith('$');

    if (key === '$set') {
      const updatedPaths = Object.keys(update[key]);
      for (const path of updatedPaths) {
        _walkUpdatePath(schema, update[key], path, update, ctx);
      }
    } else if (!isDollarKey) {
      _walkUpdatePath(schema, update, key, update, ctx);
    }

  }
};

function _walkUpdatePath(schema, op, path, update, ctx) {
  const schematype = schema.path(path);
  if (schematype == null) {
    return;
  }

  let immutable = get(schematype, 'options.immutable', null);
  if (immutable == null) {
    return;
  }
  if (typeof immutable === 'function') {
    immutable = immutable.call(ctx, ctx);
  }

  if (!immutable) {
    return;
  }

  update.$setOnInsert = update.$setOnInsert || {};
  update.$setOnInsert[path] = op[path];
  delete op[path];
}
© 2025 GrazzMean-Shell