dashpresshq/dashpress

View on GitHub
src/frontend/views/data/Create/run-initial-values-scripts.ts

Summary

Maintainability
A
0 mins
Test Coverage
F
52%
import { evalJavascriptStringSafely } from "@/shared/lib/script-runner";

export const runInitialValuesScript = (
  initialValuesScript: string,
  context: Record<string, unknown>
): Record<string, unknown> => {
  if (!initialValuesScript) {
    return {};
  }

  const response = evalJavascriptStringSafely(initialValuesScript, context);

  if (typeof response !== "object") {
    return {};
  }
  return response;
};