async function fetchSheetJSON()

in src/guFile.ts [113:126]


async function fetchSheetJSON(sheet: sheets_v4.Schema$Sheet, exportLinks: drive_v2.Schema$File['exportLinks'], id: string, title: string, auth: JWT) {
    if (!notEmpty(exportLinks)) {
        throw new Error("Missing export links")
    }
    const response = await drive.getSheet(id, sheet.properties?.title ?? "", auth)
    if (sheet.properties?.title !== 'tableDataSheet') {
        const headings = response.data.values?.[0] ?? [];
        return {[sheet.properties?.title ?? ""]: response.data.values?.slice(1).map((row) => {
            return Object.fromEntries<string>(headings.map((k, i) => [k, row[i] ?? ""]));
        }) ?? [] }
    } else {
        return {[sheet.properties.title]: response.data.values as string[][] }
    }
}