diff --git a/src/app/_components/forecast-hourly.tsx b/src/app/_components/forecast-hourly.tsx index d8a28811..4e89d815 100644 --- a/src/app/_components/forecast-hourly.tsx +++ b/src/app/_components/forecast-hourly.tsx @@ -4,11 +4,11 @@ import dayjs from "dayjs"; import { CloudSun } from "lucide-react"; import { getLocationFromLocalStorage } from "~/lib/localStorage"; +import { getWeatherForecastHourly } from "~/lib/serverActions/tomorrowio"; import { type WeatherForecastErrorResponse, type WeatherForecastHourly, - getWeatherForecastHourly, -} from "~/lib/serverActions/tomorrowio"; +} from "~/lib/types/tomorrowio"; export function ForecastHourly() { const location = useQuery({ diff --git a/src/app/_components/forecast-now.tsx b/src/app/_components/forecast-now.tsx index 2f51fb22..916d0734 100644 --- a/src/app/_components/forecast-now.tsx +++ b/src/app/_components/forecast-now.tsx @@ -5,11 +5,11 @@ import dayjs from "dayjs"; import relativeTime from "dayjs/plugin/relativeTime"; import { getLocationFromLocalStorage } from "~/lib/localStorage"; +import { getWeatherForecastNow } from "~/lib/serverActions/tomorrowio"; import { type WeatherForecastErrorResponse, type WeatherForecastNow, - getWeatherForecastNow, -} from "~/lib/serverActions/tomorrowio"; +} from "~/lib/types/tomorrowio"; dayjs.extend(relativeTime); diff --git a/src/lib/serverActions/tomorrowio.ts b/src/lib/serverActions/tomorrowio.ts index 6218c24f..9475ef8d 100644 --- a/src/lib/serverActions/tomorrowio.ts +++ b/src/lib/serverActions/tomorrowio.ts @@ -4,6 +4,15 @@ import { unstable_cache } from "next/cache"; import { env } from "~/env"; import { type Location } from "~/lib/schema"; +import { + type WeatherForecastErrorResponse, + type WeatherForecastNow, + type WeatherForecastNowResponse, + type WeatherForecastHourly, + type WeatherForecastHourlyResponse, + type WeatherForecastDaily, + type WeatherForecastDailyResponse, +} from "~/lib/types/tomorrowio"; // TODO: https://docs.tomorrow.io/reference/rate-limiting // TODO: Check fetch response status @@ -16,65 +25,6 @@ const BASE_REQUEST_OPTIONS: RequestInit = { }, }; -export type WeatherForecastErrorResponse = { - code: 429001 | number; - type: "Too Many Calls" | string; - message: string; -}; - -export type WeatherForecastNowResponse = { - data: { - time: Date; - values: { - cloudBase: number; - cloudCeiling: number; - cloudCover: number; - dewPoint: number; - freezingRainIntensity: number; - humidity: number; - precipitationProbability: number; - pressureSurfaceLevel: number; - rainIntensity: number; - sleetIntensity: number; - snowIntensity: number; - temperature: number; - temperatureApparent: number; - uvHealthConcern: number; - uvIndex: number; - visibility: number; - weatherCode: number; - windDirection: number; - windGust: number; - windSpeed: number; - }; - }; - location: { lat: number; lon: number }; -}; - -export type WeatherForecastNow = { - time: Date; - cloudBase: number; - cloudCeiling: number; - cloudCover: number; - dewPoint: number; - freezingRainIntensity: number; - humidity: number; - precipitationProbability: number; - pressureSurfaceLevel: number; - rainIntensity: number; - sleetIntensity: number; - snowIntensity: number; - temperature: number; - temperatureApparent: number; - uvHealthConcern: number; - uvIndex: number; - visibility: number; - weatherCode: number; - windDirection: number; - windGust: number; - windSpeed: number; -}; - export async function getWeatherForecastNow( location: Location, ): Promise { @@ -103,78 +53,6 @@ export async function getWeatherForecastNow( )(); } -export type WeatherForecastHourlyResponse = { - timelines: { - hourly: Array<{ - time: Date; - values: { - cloudBase: number; - cloudCeiling: number; - cloudCover: number; - dewPoint: number; - evapotranspiration: number; - freezingRainIntensity: number; - humidity: number; - iceAccumulation: number; - iceAccumulationLwe: number; - precipitationProbability: number; - pressureSurfaceLevel: number; - rainAccumulation: number; - rainAccumulationLwe: number; - rainIntensity: number; - sleetAccumulation: number; - sleetAccumulationLwe: number; - sleetIntensity: number; - snowAccumulation: number; - snowAccumulationLwe: number; - snowIntensity: number; - temperature: number; - temperatureApparent: number; - visibility: number; - weatherCode: number; - windDirection: number; - windGust: number; - windSpeed: number; - }; - }>; - }; - location: { - lat: number; - lon: number; - }; -}; - -export type WeatherForecastHourly = Array<{ - time: Date; - cloudBase: number; - cloudCeiling: number; - cloudCover: number; - dewPoint: number; - evapotranspiration: number; - freezingRainIntensity: number; - humidity: number; - iceAccumulation: number; - iceAccumulationLwe: number; - precipitationProbability: number; - pressureSurfaceLevel: number; - rainAccumulation: number; - rainAccumulationLwe: number; - rainIntensity: number; - sleetAccumulation: number; - sleetAccumulationLwe: number; - sleetIntensity: number; - snowAccumulation: number; - snowAccumulationLwe: number; - snowIntensity: number; - temperature: number; - temperatureApparent: number; - visibility: number; - weatherCode: number; - windDirection: number; - windGust: number; - windSpeed: number; -}>; - export async function getWeatherForecastHourly( location: Location, ): Promise { @@ -203,10 +81,6 @@ export async function getWeatherForecastHourly( )(); } -export type WeatherForecastDailyResponse = any; - -export type WeatherForecastDaily = any; - export async function getWeatherForecastDaily( location: Location, ): Promise { diff --git a/src/lib/types/tomorrowio.ts b/src/lib/types/tomorrowio.ts new file mode 100644 index 00000000..28e2e7b3 --- /dev/null +++ b/src/lib/types/tomorrowio.ts @@ -0,0 +1,134 @@ +export type WeatherForecastErrorResponse = { + code: 429001 | number; + type: "Too Many Calls" | string; + message: string; +}; + +export type WeatherForecastNowResponse = { + data: { + time: Date; + values: { + cloudBase: number; + cloudCeiling: number; + cloudCover: number; + dewPoint: number; + freezingRainIntensity: number; + humidity: number; + precipitationProbability: number; + pressureSurfaceLevel: number; + rainIntensity: number; + sleetIntensity: number; + snowIntensity: number; + temperature: number; + temperatureApparent: number; + uvHealthConcern: number; + uvIndex: number; + visibility: number; + weatherCode: number; + windDirection: number; + windGust: number; + windSpeed: number; + }; + }; + location: { lat: number; lon: number }; +}; + +export type WeatherForecastNow = { + time: Date; + cloudBase: number; + cloudCeiling: number; + cloudCover: number; + dewPoint: number; + freezingRainIntensity: number; + humidity: number; + precipitationProbability: number; + pressureSurfaceLevel: number; + rainIntensity: number; + sleetIntensity: number; + snowIntensity: number; + temperature: number; + temperatureApparent: number; + uvHealthConcern: number; + uvIndex: number; + visibility: number; + weatherCode: number; + windDirection: number; + windGust: number; + windSpeed: number; +}; + +export type WeatherForecastHourlyResponse = { + timelines: { + hourly: Array<{ + time: Date; + values: { + cloudBase: number; + cloudCeiling: number; + cloudCover: number; + dewPoint: number; + evapotranspiration: number; + freezingRainIntensity: number; + humidity: number; + iceAccumulation: number; + iceAccumulationLwe: number; + precipitationProbability: number; + pressureSurfaceLevel: number; + rainAccumulation: number; + rainAccumulationLwe: number; + rainIntensity: number; + sleetAccumulation: number; + sleetAccumulationLwe: number; + sleetIntensity: number; + snowAccumulation: number; + snowAccumulationLwe: number; + snowIntensity: number; + temperature: number; + temperatureApparent: number; + visibility: number; + weatherCode: number; + windDirection: number; + windGust: number; + windSpeed: number; + }; + }>; + }; + location: { + lat: number; + lon: number; + }; +}; + +export type WeatherForecastHourly = Array<{ + time: Date; + cloudBase: number; + cloudCeiling: number; + cloudCover: number; + dewPoint: number; + evapotranspiration: number; + freezingRainIntensity: number; + humidity: number; + iceAccumulation: number; + iceAccumulationLwe: number; + precipitationProbability: number; + pressureSurfaceLevel: number; + rainAccumulation: number; + rainAccumulationLwe: number; + rainIntensity: number; + sleetAccumulation: number; + sleetAccumulationLwe: number; + sleetIntensity: number; + snowAccumulation: number; + snowAccumulationLwe: number; + snowIntensity: number; + temperature: number; + temperatureApparent: number; + visibility: number; + weatherCode: number; + windDirection: number; + windGust: number; + windSpeed: number; +}>; + +export type WeatherForecastDailyResponse = any; + +export type WeatherForecastDaily = any;