text: ----------------------------
  -- Copyright (C) 2021 CARTO
  ----------------------------
  
  CREATE OR REPLACE FUNCTION _CENTEROFMASS
  (geojson STRING)
  RETURNS STRING
  LANGUAGE JAVASCRIPT
  IMMUTABLE
  AS $$
      if (!GEOJSON) {
          return null;
      }
  
      @@SF_LIBRARY_CENTER@@
  
      const center = transformationsLib.centerOfMass(JSON.parse(GEOJSON));
      return JSON.stringify(center.geometry);
  $$;
  
  CREATE OR REPLACE SECURE FUNCTION ST_CENTEROFMASS
  (geog GEOGRAPHY)
  RETURNS GEOGRAPHY
  IMMUTABLE
  AS $$
      TO_GEOGRAPHY(_CENTEROFMASS(CAST(ST_ASGEOJSON(GEOG) AS STRING)))
  $$;