PHP 8.2.30
Preview: request-parser.js Size: 1.77 KB
/proc/thread-self/root/home/byroehnu/.trash/node_modules11/adminjs/lib/backend/utils/request-parser/request-parser.js

import { FORM_VALUE_NULL, FORM_VALUE_EMPTY_OBJECT, FORM_VALUE_EMPTY_ARRAY } from '../../../frontend/hooks/use-record/params-to-form-data.js';

/**
 * Takes the original ActionRequest and convert string values to a corresponding
 * types. It
 *
 * @param {ActionRequest} originalRequest
 * @param {BaseResource}  resource
 * @returns {ActionRequest}
 *
 * @private
 */
export const requestParser = (originalRequest, resource) => {
  const {
    payload: originalPayload
  } = originalRequest;
  const payload = Object.entries(originalPayload || {}).reduce((memo, [path, formValue]) => {
    const property = resource._decorated?.getPropertyByKey(path);
    let value = formValue;
    if (formValue === FORM_VALUE_NULL) {
      value = null;
    }
    if (formValue === FORM_VALUE_EMPTY_OBJECT) {
      value = {};
    }
    if (formValue === FORM_VALUE_EMPTY_ARRAY) {
      value = [];
    }
    if (property) {
      if (property.type() === 'boolean') {
        if (value === 'true') {
          memo[path] = true;
          return memo;
        }
        if (value === 'false') {
          memo[path] = false;
          return memo;
        }
        if (value === '') {
          memo[path] = false;
          return memo;
        }
      }
      if (['date', 'datetime'].includes(property.type())) {
        if (value === '' || value === null) {
          memo[path] = null;
          return memo;
        }
      }
      if (property.type() === 'string') {
        const availableValues = property.availableValues();
        if (availableValues && !availableValues.includes(value) && value === '') {
          memo[path] = null;
          return memo;
        }
      }
    }
    memo[path] = value;
    return memo;
  }, {});
  return {
    ...originalRequest,
    payload
  };
};
export default requestParser;

Directory Contents

Dirs: 0 × Files: 3

Name Size Perms Modified Actions
36 B lrw-r--r-- 2026-02-28 00:31:42
Edit Download
1.77 KB lrw-r--r-- 2026-02-28 00:31:48
Edit Download
1.38 KB lrw-r--r-- 2026-02-28 00:31:48
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).