From 1d6ac501154c4b8d8c214f31ecd5e0e60c41902c Mon Sep 17 00:00:00 2001 From: samarmeena Date: Mon, 6 Nov 2023 14:30:31 +0530 Subject: [PATCH] refactor: corrections --- CHANGELOG.md | 8 +++++++- package.json | 2 +- src/api.ts | 24 ++++++++++++++---------- src/common/Identifiers.ts | 15 --------------- src/common/index.ts | 4 ++++ src/common/sky.ts | 15 +++++++++++++++ src/common/stations.ts | 4 +++- src/index.ts | 5 ++--- src/types/common/cloud.ts | 4 ++++ src/types/common/index.ts | 3 +++ src/types/common/station.ts | 13 +++++++++++++ src/types/index.ts | 3 +++ src/types/params/index.ts | 2 ++ src/types/params/metar.ts | 2 ++ src/types/params/taf.ts | 2 ++ src/types/response/index.ts | 2 ++ src/types/response/metar.ts | 9 +++------ src/types/response/taf.ts | 10 +++------- 18 files changed, 83 insertions(+), 44 deletions(-) delete mode 100644 src/common/Identifiers.ts create mode 100644 src/common/index.ts create mode 100644 src/common/sky.ts create mode 100644 src/types/common/cloud.ts create mode 100644 src/types/common/index.ts create mode 100644 src/types/common/station.ts create mode 100644 src/types/index.ts create mode 100644 src/types/params/index.ts create mode 100644 src/types/response/index.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 45cb39f..b21cf29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ -## 3.0.0 +# aviationweather + +## 3.0.4 ### Major Changes - migration to latest aviationweather api + +### Patch Changes + +- stations type diff --git a/package.json b/package.json index cd9ce04..cdc166d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "aviationweather", - "version": "3.0.0", + "version": "3.0.4", "description": "Node.js wrapper for aviation weather, written in TypeScript", "keywords": [ "aviation", diff --git a/src/api.ts b/src/api.ts index f820081..7b4fca9 100644 --- a/src/api.ts +++ b/src/api.ts @@ -1,25 +1,29 @@ import axios, { AxiosResponse } from "axios"; -import { TafParams } from "./types/params/taf.js"; -import { TafResponse } from "./types/response/taf.js"; -import { MetarResponse } from "./types/response/metar.js"; -import { MetarParams } from "./types/params/metar.js"; +import { + MetarParams, + MetarResponse, + TafParams, + TafResponse, +} from "./types/index.js"; export const api = axios.create({ baseURL: "https://aviationweather.gov/cgi-bin/data", }); -export function getMetar( +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export function getMetar( params: MetarParams, -): Promise> { - return api.get("/metar.php", { +): Promise> { + return api.get("/metar.php", { params, }); } -export function getTaf( +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export function getTaf( params: TafParams, -): Promise> { - return api.get("/metar.php", { +): Promise> { + return api.get("/taf.php", { params, }); } diff --git a/src/common/Identifiers.ts b/src/common/Identifiers.ts deleted file mode 100644 index 9bd1b63..0000000 --- a/src/common/Identifiers.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { IMetaSkyCondition } from "../types/common/sky.js"; - -export const skyConditions: IMetaSkyCondition[] = [ - { code: "BKN", description: "Broken cloud layer 5/8ths to 7/8ths" }, - { code: "CB", description: "Cumulonimbus" }, - { code: "CLR", description: "Sky clear at or below 12,000AGL" }, - { code: "FEW", description: "Few cloud layer 0/8ths to 2/8ths" }, - { code: "OVC", description: "Overcast cloud layer 8/8ths coverage" }, - { code: "OVCX", description: "Overcast cloud layer 8/8ths coverage" }, - { code: "SCT", description: "Scattered cloud layer 3/8ths to 4/8ths" }, - { code: "SKC", description: "Sky Clear" }, - { code: "TCU", description: "Towering Cumulus" }, - { code: "NSC", description: "No Significant Cloud" }, - { code: "CAVOK", description: "Cloud and Visibility OK" }, -]; diff --git a/src/common/index.ts b/src/common/index.ts new file mode 100644 index 0000000..5cef009 --- /dev/null +++ b/src/common/index.ts @@ -0,0 +1,4 @@ +import stations from "./stations.js"; + +export { stations }; +export * from "./sky.js"; diff --git a/src/common/sky.ts b/src/common/sky.ts new file mode 100644 index 0000000..9dd1184 --- /dev/null +++ b/src/common/sky.ts @@ -0,0 +1,15 @@ +import { IMetaSkyCondition } from "../types/common/sky.js"; + +export const skyConditions: IMetaSkyCondition[] = [ + { code: "BKN", description: "Broken cloud" }, + { code: "CB", description: "Cumulonimbus" }, + { code: "CLR", description: "Sky clear" }, + { code: "FEW", description: "Few cloud" }, + { code: "OVC", description: "Overcast cloud" }, + { code: "OVCX", description: "Overcast cloud" }, + { code: "SCT", description: "Scattered cloud" }, + { code: "SKC", description: "Sky Clear" }, + { code: "TCU", description: "Towering Cumulus" }, + { code: "NSC", description: "No Significant Cloud" }, + { code: "CAVOK", description: "Cloud and Visibility OK" }, +]; diff --git a/src/common/stations.ts b/src/common/stations.ts index f13664d..6649b50 100644 --- a/src/common/stations.ts +++ b/src/common/stations.ts @@ -1,3 +1,5 @@ +import { Station } from "../types/common/station"; + export default [ { icaoId: "32012", @@ -125917,4 +125919,4 @@ export default [ country: "US", priority: 6, }, -]; +] as Station[]; diff --git a/src/index.ts b/src/index.ts index 3f4f99c..c6677e2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,3 @@ -import stations from "./common/stations.js"; - export * from "./api.js"; -export { stations }; +export * from "./common/index.js"; +export * from "./types/index.js"; diff --git a/src/types/common/cloud.ts b/src/types/common/cloud.ts new file mode 100644 index 0000000..57d07e3 --- /dev/null +++ b/src/types/common/cloud.ts @@ -0,0 +1,4 @@ +export interface Cloud { + cover: string; + base?: number; +} diff --git a/src/types/common/index.ts b/src/types/common/index.ts new file mode 100644 index 0000000..d608f37 --- /dev/null +++ b/src/types/common/index.ts @@ -0,0 +1,3 @@ +export * from "./cloud.js"; +export * from "./sky.js"; +export * from "./station.js"; diff --git a/src/types/common/station.ts b/src/types/common/station.ts new file mode 100644 index 0000000..107ff0b --- /dev/null +++ b/src/types/common/station.ts @@ -0,0 +1,13 @@ +export interface Station { + icaoId: string; + iataId: string; + faaId: string; + wmoId: string; + lat: number; + lon: number; + elev: number; + site: string; + state: string; + country: string; + priority: number; +} diff --git a/src/types/index.ts b/src/types/index.ts new file mode 100644 index 0000000..6051231 --- /dev/null +++ b/src/types/index.ts @@ -0,0 +1,3 @@ +export * from "./common/index.js"; +export * from "./params/index.js"; +export * from "./response/index.js"; diff --git a/src/types/params/index.ts b/src/types/params/index.ts new file mode 100644 index 0000000..5b206f4 --- /dev/null +++ b/src/types/params/index.ts @@ -0,0 +1,2 @@ +export * from "./metar.js"; +export * from "./taf.js"; diff --git a/src/types/params/metar.ts b/src/types/params/metar.ts index 3195718..219fe0e 100644 --- a/src/types/params/metar.ts +++ b/src/types/params/metar.ts @@ -1,4 +1,6 @@ export interface MetarParams { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + [key: string]: any; ids: string; format?: "raw" | "json" | "geojson" | "xml" | "html"; taf?: boolean; diff --git a/src/types/params/taf.ts b/src/types/params/taf.ts index 50fb6f1..b1b2aeb 100644 --- a/src/types/params/taf.ts +++ b/src/types/params/taf.ts @@ -1,4 +1,6 @@ export interface TafParams { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + [key: string]: any; ids: string; format?: "raw" | "json" | "geojson" | "xml" | "html"; taf?: boolean; diff --git a/src/types/response/index.ts b/src/types/response/index.ts new file mode 100644 index 0000000..5b206f4 --- /dev/null +++ b/src/types/response/index.ts @@ -0,0 +1,2 @@ +export * from "./metar.js"; +export * from "./taf.js"; diff --git a/src/types/response/metar.ts b/src/types/response/metar.ts index 7174236..e011e4a 100644 --- a/src/types/response/metar.ts +++ b/src/types/response/metar.ts @@ -1,3 +1,5 @@ +import { Cloud } from "../common/cloud.js"; + export interface MetarResponse { metar_id: number; icaoId: string; @@ -9,7 +11,7 @@ export interface MetarResponse { wdir?: number; wspd?: number; wgst?: number; - visib?: number; + visib?: number | string; altim?: number; slp?: number; qcField: number; @@ -35,8 +37,3 @@ export interface MetarResponse { name: string; clouds: Cloud[]; } - -export interface Cloud { - cover: string; - base?: number; -} diff --git a/src/types/response/taf.ts b/src/types/response/taf.ts index bb791c8..ea39bfd 100644 --- a/src/types/response/taf.ts +++ b/src/types/response/taf.ts @@ -1,3 +1,5 @@ +import { Cloud } from "../common/cloud.js"; + export interface TafResponse { tafId: number; icaoId: string; @@ -30,7 +32,7 @@ export interface Fcst { wshearHgt?: number; wshearDir?: number; wshearSpd?: number; - visib: string; + visib?: number | string; altim?: number; vertVis?: number; wxString?: string; @@ -39,9 +41,3 @@ export interface Fcst { icgTurb?: number[]; temp?: number[]; } - -export interface Cloud { - cover: string; - base: number; - type?: number; -}