File tree Expand file tree Collapse file tree 5 files changed +38
-12
lines changed
Expand file tree Collapse file tree 5 files changed +38
-12
lines changed Original file line number Diff line number Diff line change 55 "main" : " dist/index.js" ,
66 "types" : " dist/index.d.ts" ,
77 "scripts" : {
8- "build" : " tsc --declaration" ,
8+ "build" : " npm run generate && tsc --declaration" ,
9+ "generate" : " ts-auto-guard src/weatherapi.ts 2>/dev/null" ,
910 "watch" : " tsc --declaration --watch" ,
1011 "prepublishOnly" : " npm run build" ,
1112 "typedoc" : " typedoc --out docs src" ,
3334 "express" : " ^4.10.4" ,
3435 "mocha" : " ^10.2.0" ,
3536 "prettier" : " ^2.8.4" ,
37+ "ts-auto-guard" : " ^4.2.0" ,
3638 "ts-node" : " ^10.9.1" ,
3739 "typedoc" : " ^0.23.23" ,
3840 "typescript" : " ^4.1.5"
Original file line number Diff line number Diff line change @@ -25,14 +25,14 @@ export * from './deltas'
2525export * from './coursetypes'
2626export * from './resourcetypes'
2727export * from './resourcesapi'
28- export { ResourceProviderRegistry } from './resourcesapi'
2928import { ResourceProviderRegistry } from './resourcesapi'
3029import { PointDestination , RouteDestination , CourseInfo } from './coursetypes'
3130
3231export * from './autopilotapi'
32+
3333export * from './weatherapi'
34- export { WeatherProviderRegistry } from './weatherapi'
3534import { WeatherProviderRegistry , WeatherWarning } from './weatherapi'
35+ export * from './weatherapi.guard'
3636
3737export type SignalKApiId =
3838 | 'resources'
Original file line number Diff line number Diff line change 1+ /*
2+ * Generated type guards for "weatherapi.ts".
3+ * WARNING: Do not manually change this file.
4+ */
5+ import { WeatherProvider } from './weatherapi'
6+
7+ export function isWeatherProvider ( obj : unknown ) : obj is WeatherProvider {
8+ const typedObj = obj as WeatherProvider
9+ return (
10+ ( ( typedObj !== null && typeof typedObj === 'object' ) ||
11+ typeof typedObj === 'function' ) &&
12+ typeof typedObj [ 'name' ] === 'string' &&
13+ ( ( typedObj [ 'methods' ] !== null &&
14+ typeof typedObj [ 'methods' ] === 'object' ) ||
15+ typeof typedObj [ 'methods' ] === 'function' ) &&
16+ ( typeof typedObj [ 'methods' ] [ 'pluginId' ] === 'undefined' ||
17+ typeof typedObj [ 'methods' ] [ 'pluginId' ] === 'string' ) &&
18+ typeof typedObj [ 'methods' ] [ 'getData' ] === 'function' &&
19+ typeof typedObj [ 'methods' ] [ 'getObservations' ] === 'function' &&
20+ typeof typedObj [ 'methods' ] [ 'getForecasts' ] === 'function' &&
21+ typeof typedObj [ 'methods' ] [ 'getWarnings' ] === 'function'
22+ )
23+ }
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ export interface WeatherProviders {
2121 }
2222}
2323
24+ /** @see {isWeatherProvider} ts-auto-guard:type-guard */
2425export interface WeatherProvider {
2526 name : string // e.g. OpenWeather, Open-Meteo, NOAA
2627 methods : WeatherProviderMethods
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ import {
1414 WeatherProviderMethods ,
1515 WeatherWarning ,
1616 WeatherData ,
17- // isWeatherProvider,
17+ isWeatherProvider ,
1818 SKVersion ,
1919 Path ,
2020 Delta ,
@@ -51,18 +51,18 @@ export class WeatherApi {
5151 if ( ! pluginId || ! provider ) {
5252 throw new Error ( `Error registering provider ${ pluginId } !` )
5353 }
54- /* if (!isWeatherProvider(provider)) {
54+ if ( ! isWeatherProvider ( provider ) ) {
5555 throw new Error (
5656 `${ pluginId } is missing WeatherProvider properties/methods!`
5757 )
58- } else {*/
59- if ( ! this . weatherProviders . has ( pluginId ) ) {
60- this . weatherProviders . set ( pluginId , provider )
61- }
62- if ( this . weatherProviders . size === 1 ) {
63- this . defaultProviderId = pluginId
58+ } else {
59+ if ( ! this . weatherProviders . has ( pluginId ) ) {
60+ this . weatherProviders . set ( pluginId , provider )
61+ }
62+ if ( this . weatherProviders . size === 1 ) {
63+ this . defaultProviderId = pluginId
64+ }
6465 }
65- //}
6666 debug ( `No. of WeatherProviders registered =` , this . weatherProviders . size )
6767 }
6868
You can’t perform that action at this time.
0 commit comments