Skip to content

Commit 404d88f

Browse files
feat: begin amdb module
1 parent ff30234 commit 404d88f

19 files changed

+1042
-0
lines changed

packages/amdb/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# @navigraph/amdb
2+
3+
## 0.0.1
4+
5+
### Patch Changes
6+
7+
-

packages/amdb/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# @navigraph/amdb
2+
3+
This package is part of the Navigraph SDK, and is intended to be used in conjuction with other SDK modules.
4+
See the [navigraph](https://www.npmjs.com/package/navigraph) package for usage.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"replace": {
3+
"main": "dist/index.cjs.js",
4+
"module": "dist/index.esm.js",
5+
"types": "dist/index.d.ts",
6+
"exports": {
7+
".": {
8+
"import": "./dist/index.esm.js",
9+
"require": "./dist/index.cjs.js"
10+
},
11+
"./package.json": "./package.json"
12+
}
13+
}
14+
}

packages/amdb/jest.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/** @type {import("ts-jest").JestConfigWithTsJest} */
2+
module.exports = {
3+
displayName: "AMDB",
4+
preset: "ts-jest",
5+
}

packages/amdb/package.json

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"name": "@navigraph/amdb",
3+
"version": "0.0.1",
4+
"license": "MIT",
5+
"description": "Allows interaction with the Navigraph AMDB API as part of the Navigraph SDK",
6+
"author": "Navigraph <[email protected]> (https://navigraph.com)",
7+
"homepage": "https://navigraph.com",
8+
"repository": {
9+
"type": "git",
10+
"url": "https://github.com/Navigraph/navigraph-js-sdk",
11+
"directory": "packages/amdb"
12+
},
13+
"keywords": [
14+
"navigraph",
15+
"oans",
16+
"amm",
17+
"airport",
18+
"AIRAC",
19+
"sdk"
20+
],
21+
"main": "./src/index.ts",
22+
"private": false,
23+
"sideEffects": false,
24+
"files": [
25+
"dist/**"
26+
],
27+
"publishConfig": {
28+
"access": "public"
29+
},
30+
"scripts": {
31+
"build": "tsup src/index.ts --dts",
32+
"dev": "tsup src/index.ts --watch --sourcemap inline",
33+
"lint": "eslint \"src/**/*.ts\"",
34+
"clean": "rimraf .turbo node_modules dist",
35+
"prepack": "clean-package",
36+
"postpack": "clean-package restore"
37+
},
38+
"dependencies": {
39+
"@navigraph/app": "1.3.5",
40+
"@navigraph/auth": "2.5.1",
41+
"geojson": "^0.5.0"
42+
}
43+
}

packages/amdb/src/api/getAmdbLayer.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { Logger } from "@navigraph/app"
2+
import { isAxiosError, navigraphRequest } from "@navigraph/auth"
3+
import { getAmdbApiRoot } from "../constants"
4+
import { AmdbLayerName, AmdbResult, Projection } from "../types"
5+
6+
export default async function getAmdbLayer<L extends AmdbLayerName>({
7+
icao,
8+
projection,
9+
layer,
10+
precision,
11+
}: {
12+
icao: string
13+
layer: L
14+
projection?: Projection
15+
precision?: number
16+
}) {
17+
const result = await navigraphRequest
18+
.get<AmdbResult<L>[L]>(`${getAmdbApiRoot()}/${icao}/${layer}`, {
19+
params: {
20+
projection,
21+
precision,
22+
},
23+
})
24+
.catch((e: unknown) => Logger.err("Failed to fetch amdb layers. Reason:", isAxiosError(e) ? e.message : e))
25+
26+
return result?.data || null
27+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { Logger } from "@navigraph/app"
2+
import { isAxiosError, navigraphRequest } from "@navigraph/auth"
3+
import { getAmdbApiRoot } from "../constants"
4+
import { AmdbLayerName, AmdbResult, Projection } from "../types"
5+
6+
export default async function getAmdbLayers<
7+
I extends AmdbLayerName[] | undefined = undefined,
8+
E extends AmdbLayerName[] | undefined = undefined,
9+
>({
10+
icao,
11+
include,
12+
exclude,
13+
projection,
14+
precision,
15+
}: {
16+
icao: string
17+
include?: I
18+
exclude?: E
19+
projection?: Projection
20+
precision?: number
21+
}) {
22+
type Result = AmdbResult<
23+
I extends AmdbLayerName[]
24+
? I[number]
25+
: E extends AmdbLayerName[]
26+
? Exclude<AmdbLayerName, E[number]>
27+
: AmdbLayerName
28+
>
29+
30+
const result = await navigraphRequest
31+
.get<Result>(`${getAmdbApiRoot()}/${icao}`, {
32+
params: {
33+
include: include?.join(","),
34+
exclude: exclude?.join(","),
35+
projection,
36+
precision,
37+
},
38+
})
39+
.catch((e: unknown) => Logger.err("Failed to fetch amdb layers. Reason:", isAxiosError(e) ? e.message : e))
40+
41+
return result?.data || null
42+
}

packages/amdb/src/constants.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { getDefaultAppDomain } from "@navigraph/app"
2+
3+
export const getAmdbApiRoot = () => `https://amdb.api.${getDefaultAppDomain()}/v1`
4+
export const getInfoApiRoot = () => `https://amdb.api.${getDefaultAppDomain()}/info`

packages/amdb/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export * from "./types"
2+
3+
export { getAmdbAPI } from "./lib/getAmdbAPI"

packages/amdb/src/lib/getAmdbAPI.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { getApp, Logger, NotInitializedError, Scope } from "@navigraph/app"
2+
import getAmdbLayer from "../api/getAmdbLayer"
3+
import getAmdbLayers from "../api/getAmdbLayers"
4+
5+
/** Grabs a reference to an object containing available Navigraph Charts API functionality */
6+
export const getAmdbAPI = () => {
7+
const app = getApp()
8+
9+
if (!app) {
10+
throw new NotInitializedError("Auth")
11+
} else if (!app.scopes.includes(Scope.AMDB)) {
12+
Logger.warning(
13+
"Your Navigraph Application does not have the AMDB scope. Attempts to access the AMDB API will fail.",
14+
)
15+
}
16+
17+
return {
18+
getAmdbLayer,
19+
getAmdbLayers,
20+
}
21+
}

0 commit comments

Comments
 (0)