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.32 [ PHP INFO ] PHP os: Linux
Server Ip: 162.213.251.212
Your Ip: 18.191.251.36
User: allssztx (535) | Group: allssztx (533)
Safe Mode: OFF
Disable Function:
NONE

name : stringifyFunctionOperators.js
'use strict';

module.exports = function stringifyFunctionOperators(pipeline) {
  if (!Array.isArray(pipeline)) {
    return;
  }

  for (const stage of pipeline) {
    if (stage == null) {
      continue;
    }

    const canHaveAccumulator = stage.$group || stage.$bucket || stage.$bucketAuto;
    if (canHaveAccumulator != null) {
      for (const key of Object.keys(canHaveAccumulator)) {
        handleAccumulator(canHaveAccumulator[key]);
      }
    }

    const stageType = Object.keys(stage)[0];
    if (stageType && typeof stage[stageType] === 'object') {
      const stageOptions = stage[stageType];
      for (const key of Object.keys(stageOptions)) {
        if (stageOptions[key] != null &&
            stageOptions[key].$function != null &&
            typeof stageOptions[key].$function.body === 'function') {
          stageOptions[key].$function.body = stageOptions[key].$function.body.toString();
        }
      }
    }

    if (stage.$facet != null) {
      for (const key of Object.keys(stage.$facet)) {
        stringifyFunctionOperators(stage.$facet[key]);
      }
    }
  }
};

function handleAccumulator(operator) {
  if (operator == null || operator.$accumulator == null) {
    return;
  }

  for (const key of ['init', 'accumulate', 'merge', 'finalize']) {
    if (typeof operator.$accumulator[key] === 'function') {
      operator.$accumulator[key] = String(operator.$accumulator[key]);
    }
  }
}
© 2025 GrazzMean-Shell