Commit 07f4d6c9 authored by Massimo Costantini's avatar Massimo Costantini
Browse files

corrected CPS

parent f9182f75
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -163,14 +163,14 @@ const IVOA_syncEndpoint = (req) => async (IO) => {
};

/**
 * Generates a VOTable error document for /tap/sync.
 * Generates a VOTable XML error document for synchronous TAP responses.
 *
 * Functional signature: String -> IO -> IO String
 * Functional signature: String -> String
 *
 * @param {string} message - Error message to embed in the VOTable
 * @returns {(IO) => Promise<string>} - A CPS IO action returning an XML error document
 * @param {string} message - The error message to embed in the VOTable
 * @returns {string} - The XML error response as a serialized string
 */
function makeSyncError(message) {
export function makeSyncError(message) {
  return xmlbuilder
    .create("VOTABLE", { encoding: "UTF-8" })
    .att("version", "1.3")
+24 −28
Original line number Diff line number Diff line
@@ -105,20 +105,18 @@ def ivoa_tables_endpoint(req) -> Callable[[object], Awaitable[str]]:
    return inner


def make_sync_error(message: str) -> Callable[[object], Awaitable[str]]:
def make_sync_error(message: str) -> str:
    """
    Generates a VOTable error document for /tap/sync.
    Generates a VOTable XML error document for synchronous TAP responses.

    Functional signature: String -> IO -> IO String
    Functional signature: String -> String

    Args:
        message: Error message to embed in the VOTable.
        message: The error message to embed in the VOTable.

    Returns:
        Callable[[object], Awaitable[str]]: A CPS IO action returning an XML error document.
        The XML error response as a serialized string,
    """

    async def inner(io):
    votable = ET.Element(
        "VOTABLE",
        {
@@ -129,14 +127,12 @@ def make_sync_error(message: str) -> Callable[[object], Awaitable[str]]:
        },
    )
    resource = ET.SubElement(votable, "RESOURCE", {"type": "results"})
        ET.SubElement(
            resource, "INFO", {"name": "QUERY_STATUS", "value": "ERROR"}
        ).text = message
    ET.SubElement(resource, "INFO", {"name": "QUERY_STATUS", "value": "ERROR"}).text = (
        message
    )
    xml_str = ET.tostring(votable, encoding="utf-8")
    return minidom.parseString(xml_str).toprettyxml(indent="  ")

    return inner


def ivoa_sync_endpoint(req) -> Callable[[object], Awaitable[str]]:
    """
@@ -166,19 +162,19 @@ def ivoa_sync_endpoint(req) -> Callable[[object], Awaitable[str]]:
        )

        if not query:
            return await make_sync_error("Missing QUERY parameter")(io)
            return make_sync_error("Missing QUERY parameter")

        if request_type != "doQuery":
            return await make_sync_error(
            return make_sync_error(
                'The parameter "request" must be "doQuery" or omitted'
            )(io)
            )

        conn = await conn_postgresql()(io)
        result = await fetch_query_result(conn, query, [])(io)
        await quit_postgresql(conn)(io)

        if result["tag"] == "nothing":
            return await make_sync_error("No results.")(io)
            return make_sync_error("No results.")

        fields = result["value"]["fields"]
        rows = result["value"]["rows"]
+1 −1
Original line number Diff line number Diff line
@@ -11,7 +11,7 @@ import xmlbuilder from "xmlbuilder";
 *
 * Functional signature: { fields: List Field, rows: List Row } -> String
 *
 * @param {{ fields: Array<{ name: string }>, rows: Array<Object> }} param0 - Object containing field definitions and row data
 * @param {{ fields: Array<{ name: string }>, rows: Array<Object> }} input - Object containing field definitions and row data
 * @returns {string} - An XML string in the VOSI TableSet format
 */
export const buildVOTablesFromRows = ({ fields, rows }) => {
+3 −7
Original line number Diff line number Diff line
@@ -6,22 +6,18 @@ from xml.dom import minidom
import xml.etree.ElementTree as ET


def build_votables_from_rows(
    fields: List[Dict[str, str]], rows: List[Dict[str, str]]
) -> str:
def build_votables_from_rows(fields, rows):
    """
    Builds a VOSI TableSet XML string from a list of table/column metadata rows.

    Functional signature: List Field -> List Row -> String
    Functional signature: { fields : List Field, rows : List Row } -> String

    Args:
        fields: A list of field definitions (each with a 'name' key).
        rows: A list of dictionaries representing rows with keys corresponding to fields.
              Each row is expected to include:
              [schema_name, table_name, table_type, column_name, datatype, description]

    Returns:
        str: A formatted XML string in the VOSI TableSet format.
        An XML string in the VOSI TableSet format.
    """
    grouped = {}