Skip to content

Commit

Permalink
⚒️ finish refactoring of moving types into their own package
Browse files Browse the repository at this point in the history
  • Loading branch information
danyx23 committed Dec 29, 2023
1 parent 5259b57 commit 9fa04c2
Show file tree
Hide file tree
Showing 39 changed files with 762 additions and 520 deletions.
130 changes: 130 additions & 0 deletions packages/@ourworldindata/types/src/OwidVariable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import { OwidOrigin } from "./OwidOrigin.js"
import { OwidSource } from "./OwidSource.js"
import { OwidVariableDisplayConfigInterface } from "./OwidVariableDisplayConfigInterface.js"

export interface OwidVariableWithSource {
id: number
name?: string
description?: string
descriptionShort?: string
descriptionFromProducer?: string
descriptionKey?: string[]
descriptionProcessing?: string
unit?: string
display?: OwidVariableDisplayConfigInterface
shortUnit?: string
datasetName?: string
datasetId?: number
coverage?: string
nonRedistributable?: boolean
source?: OwidSource
origins?: OwidOrigin[]
schemaVersion?: number
processingLevel?: OwidProcessingLevel
presentation?: OwidVariablePresentation
shortName?: string
timespan?: string
catalogPath?: string
license?: OwidLicense
updatePeriodDays?: number
datasetVersion?: string
licenses?: OwidLicense[]

// omitted:
// code
// coverage
// dataPath
// metadataPath
}

export interface IndicatorTitleWithFragments {
title: string
attributionShort?: string
titleVariant?: string
}

export function joinTitleFragments(
attributionShort: string | undefined,
titleVariant: string | undefined
): string | undefined {
if (attributionShort && titleVariant && attributionShort !== titleVariant) {
return `${titleVariant}${attributionShort}`
}
if (attributionShort) {
return attributionShort
}
if (titleVariant) {
return titleVariant
}
return undefined
}

export interface OwidLicense {
name: string
url: string
}

export interface OwidVariablePresentation {
titlePublic?: string
titleVariant?: string
attributionShort?: string
attribution?: string
topicTagsLinks?: string[]
faqs?: FaqLink[]
grapherConfigETL?: string
}

export type OwidProcessingLevel = "minor" | "major"

export interface FaqLink {
gdocId: string
fragmentId: string
}

export type OwidVariableWithSourceAndDimension = OwidVariableWithSource & {
dimensions: OwidVariableDimensions
}

export type OwidVariableWithSourceAndDimensionWithoutId = Omit<
OwidVariableWithSourceAndDimension,
"id"
>

export interface OwidVariableMixedData {
years: number[]
entities: number[]
values: (string | number)[]
}

export type OwidVariableWithDataAndSource = OwidVariableWithSource &
OwidVariableMixedData

export interface OwidVariableDimension {
values: OwidVariableDimensionValuePartial[]
}

export interface OwidVariableDimensions {
years: OwidVariableDimension
entities: OwidVariableDimension
}

export type OwidVariableDataMetadataDimensions = {
data: OwidVariableMixedData
metadata: OwidVariableWithSourceAndDimension
}
export type MultipleOwidVariableDataDimensionsMap = Map<
number,
OwidVariableDataMetadataDimensions
>

export interface OwidVariableDimensionValuePartial {
id: number
name?: string
code?: string
}
export type OwidVariableDimensionValueFull =
Required<OwidVariableDimensionValuePartial>

export interface OwidEntityKey {
[id: string]: OwidVariableDimensionValuePartial
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { OwidVariableId } from "./domainTypes/Various.js"
import {
ColumnSlug,
DimensionProperty,
OwidVariableId,
Time,
} from "./owidTypes.js"
} from "./grapherTypes/GrapherTypes.js"

export interface OwidVariableDisplayConfigInterface {
name?: string
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { KeyChartLevel } from "../domainTypes/Charts.js"
import { KeyChartLevel } from "../grapherTypes/GrapherTypes.js"
import { Tag } from "./Tags.js"

/** the entity in the `chart_tags` table */
export interface ChartTag {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { FormattingOptions } from "@ourworldindata/types"
import { WP_PostType } from "../wordpress/WordpressTypes.js"
import {
OwidArticleBackportingStatistics,
OwidGdocPostInterface,
} from "../gdocTypes/Gdoc.js"
import { FormattingOptions } from "../Wordpress.js"

export interface PostRowPlainFields {
id: number
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FormattingOptions } from "@ourworldindata/types"
import { FormattingOptions } from "../Wordpress.js"
import { PostRowEnriched, PostRowRaw } from "./Posts.js"

export function parsePostFormattingOptions(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { OwidGdocType } from "../gdocTypes/Gdoc.js"
import { WP_PostType } from "../wordpress/WordpressTypes.js"
import { RelatedChart } from "./Charts.js"
import { RelatedChart } from "../grapherTypes/GrapherTypes.js"
import { TocHeading } from "./Toc.js"

export interface FormattedPost extends FullPost {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
IndicatorTitleWithFragments,
OwidProcessingLevel,
} from "../OwidVariable.js"
import { RelatedChart } from "../domainTypes/Charts.js"
import { RelatedChart } from "../grapherTypes/GrapherTypes.js"
import { Static, Type } from "@sinclair/typebox"
import { OwidGdocPostInterface } from "./Gdoc.js"
import { OwidEnrichedGdocBlock } from "./ArchieMlComponents.js"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Tag } from "../dbTypes/Tags.js"
import { RelatedChart } from "../domainTypes/Charts.js"
import { RelatedChart } from "../grapherTypes/GrapherTypes.js"
import { BreadcrumbItem } from "../domainTypes/Site.js"
import { TocHeadingWithTitleSupertitle } from "../domainTypes/Toc.js"
import { ImageMetadata } from "../image.js"
import { ImageMetadata } from "./Image.js"
import {
EnrichedBlockText,
EnrichedBlockWithParseErrors,
Expand Down
20 changes: 20 additions & 0 deletions packages/@ourworldindata/types/src/gdocTypes/Image.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// This is the JSON we get from Google's API before remapping the keys to be consistent with the rest of our interfaces
export interface GDriveImageMetadata {
name: string // -> filename
modifiedTime: string // -> updatedAt e.g. "2023-01-11T19:45:27.000Z"
id: string // -> googleId e.g. "1dfArzg3JrAJupVl4YyJpb2FOnBn4irPX"
description?: string // -> defaultAlt
imageMediaMetadata?: {
width?: number // -> originalWidth
}
}

export interface ImageMetadata {
googleId: string
filename: string
defaultAlt: string
// MySQL Date objects round to the nearest second, whereas Google includes milliseconds
// so we store as an epoch to avoid any conversion issues
updatedAt: number
originalWidth?: number
}
Loading

0 comments on commit 9fa04c2

Please sign in to comment.