diff --git a/functions/_common/env.ts b/functions/_common/env.ts index bee51a26249..a26d303d84c 100644 --- a/functions/_common/env.ts +++ b/functions/_common/env.ts @@ -19,3 +19,4 @@ export const extensions = { readme: ".readme.md", zip: ".zip", } +export type Etag = string diff --git a/functions/_common/fetchMetadataForGrapher.ts b/functions/_common/fetchMetadataForGrapher.ts index 6052150d767..5df70979517 100644 --- a/functions/_common/fetchMetadataForGrapher.ts +++ b/functions/_common/fetchMetadataForGrapher.ts @@ -1,7 +1,7 @@ import { Grapher } from "@ourworldindata/grapher" import { OwidColumnDef } from "@ourworldindata/types" import { StatusError } from "itty-router" -import { createZip } from "littlezipper" +import { createZip, File } from "littlezipper" import { assembleMetadata, getColumnsForMetadata } from "./metadataTools.js" import { Env } from "./env.js" import { GrapherIdentifier, initGrapher } from "./grapherTools.js" diff --git a/functions/_common/grapherRenderer.ts b/functions/_common/grapherRenderer.ts index 8523f2fbe62..c56b214755a 100644 --- a/functions/_common/grapherRenderer.ts +++ b/functions/_common/grapherRenderer.ts @@ -1,7 +1,6 @@ import { svg2png, initialize as initializeSvg2Png } from "svg2png-wasm" import { TimeLogger } from "./timeLogger" import { png } from "itty-router" -import { File } from "littlezipper" import svg2png_wasm from "../../node_modules/svg2png-wasm/svg2png_wasm_bg.wasm" @@ -19,8 +18,6 @@ declare global { var window: any } -export type Etag = string - export const grapherBaseUrl = "https://ourworldindata.org/grapher" // Lots of defaults; these are mostly the same as they are in owid-grapher. diff --git a/functions/_common/metadataTools.ts b/functions/_common/metadataTools.ts index d67019a2157..e3ac39e965b 100644 --- a/functions/_common/metadataTools.ts +++ b/functions/_common/metadataTools.ts @@ -12,6 +12,22 @@ import { getCitationLong, } from "@ourworldindata/utils" +interface MetadataColumn { + titleShort: string + titleLong: string + descriptionShort: string + descriptionKey: string[] + descriptionProcessing: string + shortUnit: string + unit: string + timespan: string + tolerance: number + type: string + conversionFactor: number + owidVariableId: number + shortName: string +} + export const getColumnsForMetadata = (grapher: Grapher) => { const columnsToIgnore = new Set( [ @@ -40,37 +56,7 @@ export function assembleMetadata( const metadataCols = getColumnsForMetadata(grapher) - const columns: [ - string, - { - title: string - titleProducer: string - titleVariant: string - descriptionShort: string - descriptionFromProducer: string - descriptionKey: string[] - descriptionProcessing: string - shortUnit: string - unit: string - timespan: string - tolerance: number - type: string - conversionFactor: number - owidVariableId: number - catalogPath: string - sources: Partial< - Pick< - OwidOrigin, - | "attribution" - | "attributionShort" - | "description" - | "urlDownload" - | "urlMain" - > - >[] - shortName: string - }, - ][] = metadataCols.map((col) => { + const columns: [string, MetadataColumn][] = metadataCols.map((col) => { console.log("mapping col", col.name) const { descriptionShort, diff --git a/functions/_common/reusableHandlers.ts b/functions/_common/reusableHandlers.ts index 9c0f311815e..06d7da77335 100644 --- a/functions/_common/reusableHandlers.ts +++ b/functions/_common/reusableHandlers.ts @@ -1,5 +1,5 @@ -import { Env } from "./env.js" -import { Etag, fetchAndRenderGrapher } from "./grapherRenderer.js" +import { Env, Etag } from "./env.js" +import { fetchAndRenderGrapher } from "./grapherRenderer.js" import { GrapherIdentifier } from "./grapherTools.js" export async function handleThumbnailRequest( diff --git a/functions/grapher/[slug].ts b/functions/grapher/[slug].ts index cebee59635e..2e1e68b78cf 100644 --- a/functions/grapher/[slug].ts +++ b/functions/grapher/[slug].ts @@ -1,5 +1,4 @@ -import { Env, extensions } from "../_common/env.js" -import { Etag } from "../_common/grapherRenderer.js" +import { Env, extensions, Etag } from "../_common/env.js" import { fetchCsvForGrapher, fetchMetadataForGrapher, diff --git a/functions/grapher/by-uuid/[uuid].ts b/functions/grapher/by-uuid/[uuid].ts index c3c3e11d21b..352813a0b70 100644 --- a/functions/grapher/by-uuid/[uuid].ts +++ b/functions/grapher/by-uuid/[uuid].ts @@ -1,5 +1,4 @@ -import { Env } from "../../_common/env.js" -import { extensions } from "../../_common/env.js" +import { Env, extensions } from "../../_common/env.js" import { fetchGrapherConfig } from "../../_common/grapherTools.js" import { IRequestStrict, Router, error, StatusError } from "itty-router" import { handleThumbnailRequest } from "../../_common/reusableHandlers.js"