function recordsToRows(records, definitionHeaders) {
        const headers = []
        const rows = []
        let addHeaders = true

        for(let i = 0; i < records.length; i++) {
            addHeaders = i == 0
            const record = records[i]
            rows.push(recordToRow(record, headers, addHeaders).join(','))
        }

        return [headers.join(',')].concat(rows)

        /**
         * 
         * @param {[string,RecordValue][]} record
         * @param {string[]} headers
         * @param {boolean} addHeaders
         * @returns {string[]}
         */
        function recordToRow(record, headers, addHeaders) {
            const row = []
            for(let i = 0; i < record.length; i++) {
                const key = record[i][0]
                if(addHeaders) {
                    const headerMatch = definitionHeaders.filter(x => x.name == key)
                    if(headerMatch.length == 1) {
                        headers.push(headerMatch[0].label)
                    }
                    else {
                        headers.push(key)
                    }
                }
                row.push(record[i][1].value)
            }
            return row
        }
    }
@param {[string, RecordValue][][]} records 
@param {{
 label: string, 
 name: string
}[]} definitionHeaders
@returns {string[]}