Skip to content

Commit

Permalink
refactor: corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
samarmeena committed Nov 6, 2023
1 parent 16ddbfb commit 1d6ac50
Show file tree
Hide file tree
Showing 18 changed files with 83 additions and 44 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## 3.0.0
# aviationweather

## 3.0.4

### Major Changes

- migration to latest aviationweather api

### Patch Changes

- stations type
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
24 changes: 14 additions & 10 deletions src/api.ts
Original file line number Diff line number Diff line change
@@ -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<T = MetarResponse[]>(
params: MetarParams,
): Promise<AxiosResponse<MetarResponse[]>> {
return api.get<MetarResponse[]>("/metar.php", {
): Promise<AxiosResponse<T>> {
return api.get<T>("/metar.php", {
params,
});
}

export function getTaf(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function getTaf<T = TafResponse[]>(
params: TafParams,
): Promise<AxiosResponse<TafResponse[]>> {
return api.get<TafResponse[]>("/metar.php", {
): Promise<AxiosResponse<T>> {
return api.get<T>("/taf.php", {
params,
});
}
15 changes: 0 additions & 15 deletions src/common/Identifiers.ts

This file was deleted.

4 changes: 4 additions & 0 deletions src/common/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import stations from "./stations.js";

export { stations };
export * from "./sky.js";
15 changes: 15 additions & 0 deletions src/common/sky.ts
Original file line number Diff line number Diff line change
@@ -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" },
];
4 changes: 3 additions & 1 deletion src/common/stations.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Station } from "../types/common/station";

export default [
{
icaoId: "32012",
Expand Down Expand Up @@ -125917,4 +125919,4 @@ export default [
country: "US",
priority: 6,
},
];
] as Station[];
5 changes: 2 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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";
4 changes: 4 additions & 0 deletions src/types/common/cloud.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface Cloud {
cover: string;
base?: number;
}
3 changes: 3 additions & 0 deletions src/types/common/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from "./cloud.js";
export * from "./sky.js";
export * from "./station.js";
13 changes: 13 additions & 0 deletions src/types/common/station.ts
Original file line number Diff line number Diff line change
@@ -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;
}
3 changes: 3 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from "./common/index.js";
export * from "./params/index.js";
export * from "./response/index.js";
2 changes: 2 additions & 0 deletions src/types/params/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./metar.js";
export * from "./taf.js";
2 changes: 2 additions & 0 deletions src/types/params/metar.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/types/params/taf.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/types/response/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./metar.js";
export * from "./taf.js";
9 changes: 3 additions & 6 deletions src/types/response/metar.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Cloud } from "../common/cloud.js";

export interface MetarResponse {
metar_id: number;
icaoId: string;
Expand All @@ -9,7 +11,7 @@ export interface MetarResponse {
wdir?: number;
wspd?: number;
wgst?: number;
visib?: number;
visib?: number | string;
altim?: number;
slp?: number;
qcField: number;
Expand All @@ -35,8 +37,3 @@ export interface MetarResponse {
name: string;
clouds: Cloud[];
}

export interface Cloud {
cover: string;
base?: number;
}
10 changes: 3 additions & 7 deletions src/types/response/taf.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Cloud } from "../common/cloud.js";

export interface TafResponse {
tafId: number;
icaoId: string;
Expand Down Expand Up @@ -30,7 +32,7 @@ export interface Fcst {
wshearHgt?: number;
wshearDir?: number;
wshearSpd?: number;
visib: string;
visib?: number | string;
altim?: number;
vertVis?: number;
wxString?: string;
Expand All @@ -39,9 +41,3 @@ export interface Fcst {
icgTurb?: number[];
temp?: number[];
}

export interface Cloud {
cover: string;
base: number;
type?: number;
}

0 comments on commit 1d6ac50

Please sign in to comment.