@mharj/openweathermap 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  import { CountryCode, LangCode, Loadable, WeatherDataV2 } from './types';
2
- import { Result } from 'mharj-result';
2
+ import { Result } from '@luolapeikko/result-option';
3
3
  import type { ICacheOrAsync } from '@avanio/expire-cache';
4
4
  import type { IOpenWeatherV2 } from './interfaces/IOpenWeatherV2';
5
5
  /**
@@ -2,9 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.OpenWeatherV2 = void 0;
4
4
  const types_1 = require("./types");
5
- const mharj_result_1 = require("mharj-result");
5
+ const result_option_1 = require("@luolapeikko/result-option");
6
6
  const fetchUtils_1 = require("./lib/fetchUtils");
7
- const fetchResult = (0, mharj_result_1.safeAsyncResultBuilder)(fetch);
7
+ const fetchResult = (0, result_option_1.safeAsyncResultBuilder)(fetch);
8
8
  function isJson(response) {
9
9
  const contentType = response.headers.get('content-type');
10
10
  return (contentType && contentType.startsWith('application/json')) || false;
@@ -26,28 +26,28 @@ const defaultImplementation = {
26
26
  const logUrl = buildLogUrl(params);
27
27
  const result = await fetchResult(buildUrl(params));
28
28
  if (!result.isOk) {
29
- return (0, mharj_result_1.Err)(result.err());
29
+ return (0, result_option_1.Err)(result.err());
30
30
  }
31
31
  const res = result.ok();
32
32
  if (!res.ok) {
33
33
  if (isJson(res)) {
34
34
  const data = await res.json();
35
35
  if (isOpenWeatherError(data)) {
36
- return (0, mharj_result_1.Err)(new TypeError(`OpenWeatherV2 error: ${data.message} from ${logUrl}`));
36
+ return (0, result_option_1.Err)(new TypeError(`OpenWeatherV2 error: ${data.message} from ${logUrl}`));
37
37
  }
38
38
  }
39
- return (0, mharj_result_1.Err)(new TypeError(`OpenWeatherV2 http error: ${res.status} ${res.statusText} from ${logUrl}`));
39
+ return (0, result_option_1.Err)(new TypeError(`OpenWeatherV2 http error: ${res.status} ${res.statusText} from ${logUrl}`));
40
40
  }
41
41
  if (!isJson(res)) {
42
- return (0, mharj_result_1.Err)(new TypeError(`OpenWeatherV2 response is not json payload from ${logUrl}`));
42
+ return (0, result_option_1.Err)(new TypeError(`OpenWeatherV2 response is not json payload from ${logUrl}`));
43
43
  }
44
- const jsonResult = await (0, mharj_result_1.safeAsyncResult)(res.json());
44
+ const jsonResult = await (0, result_option_1.safeAsyncResult)(res.json());
45
45
  if (!jsonResult.isOk) {
46
- return (0, mharj_result_1.Err)(jsonResult.err());
46
+ return (0, result_option_1.Err)(jsonResult.err());
47
47
  }
48
48
  const data = jsonResult.ok();
49
49
  (0, types_1.assertWeatherDataV2)(data);
50
- return (0, mharj_result_1.Ok)(data);
50
+ return (0, result_option_1.Ok)(data);
51
51
  },
52
52
  };
53
53
  /**
@@ -111,10 +111,10 @@ class OpenWeatherV2 {
111
111
  params.append('id', String(id));
112
112
  cacheEntry = await this.handleFetch(cacheKey, params, opts);
113
113
  }
114
- return (0, mharj_result_1.Ok)(cacheEntry);
114
+ return (0, result_option_1.Ok)(cacheEntry);
115
115
  }
116
116
  catch (err) {
117
- return (0, mharj_result_1.Err)((0, fetchUtils_1.fetchErrorWrapper)(err));
117
+ return (0, result_option_1.Err)((0, fetchUtils_1.fetchErrorWrapper)(err));
118
118
  }
119
119
  }
120
120
  /**
@@ -140,10 +140,10 @@ class OpenWeatherV2 {
140
140
  params.append('q', countryCode ? `${city},${countryCode}` : city);
141
141
  cacheEntry = await this.handleFetch(cacheKey, params, opts);
142
142
  }
143
- return (0, mharj_result_1.Ok)(cacheEntry);
143
+ return (0, result_option_1.Ok)(cacheEntry);
144
144
  }
145
145
  catch (err) {
146
- return (0, mharj_result_1.Err)((0, fetchUtils_1.fetchErrorWrapper)(err));
146
+ return (0, result_option_1.Err)((0, fetchUtils_1.fetchErrorWrapper)(err));
147
147
  }
148
148
  }
149
149
  /**
@@ -170,10 +170,10 @@ class OpenWeatherV2 {
170
170
  params.append('lon', String(lon));
171
171
  cacheEntry = await this.handleFetch(cacheKey, params, opts);
172
172
  }
173
- return (0, mharj_result_1.Ok)(cacheEntry);
173
+ return (0, result_option_1.Ok)(cacheEntry);
174
174
  }
175
175
  catch (err) {
176
- return (0, mharj_result_1.Err)((0, fetchUtils_1.fetchErrorWrapper)(err));
176
+ return (0, result_option_1.Err)((0, fetchUtils_1.fetchErrorWrapper)(err));
177
177
  }
178
178
  }
179
179
  async buildBaseParams({ lang, units }) {
@@ -1 +1 @@
1
- {"version":3,"file":"OpenWeatherV2.js","sourceRoot":"./src/","sources":["OpenWeatherV2.ts"],"names":[],"mappings":";;;AAAA,mCAA4F;AAC5F,+CAAsF;AACtF,iDAAmD;AAInD,MAAM,WAAW,GAAG,IAAA,qCAAsB,EAA8D,KAAK,CAAC,CAAC;AAE/G,SAAS,MAAM,CAAC,QAAkB;IACjC,MAAM,WAAW,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IACzD,OAAO,CAAC,WAAW,IAAI,WAAW,CAAC,UAAU,CAAC,kBAAkB,CAAC,CAAC,IAAI,KAAK,CAAC;AAC7E,CAAC;AAED,SAAS,kBAAkB,CAAC,IAAa;IACxC,OAAO,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,SAAS,IAAI,IAAI,CAAC;AACxF,CAAC;AAmBD,MAAM,QAAQ,GAAG,iDAAiD,CAAC;AAEnE,SAAS,QAAQ,CAAC,MAAuB;IACxC,OAAO,GAAG,QAAQ,IAAI,MAAM,CAAC,QAAQ,EAAE,EAAE,CAAC;AAC3C,CAAC;AAED,SAAS,WAAW,CAAC,MAAuB;IAC3C,MAAM,SAAS,GAAG,IAAI,eAAe,CAAC,MAAM,CAAC,CAAC;IAC9C,SAAS,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAC9B,OAAO,QAAQ,CAAC,SAAS,CAAC,CA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IAAgC;QACpG,yDAAyD;QACzD,IAAI,aAAa,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACvD,IAAI,CAAC,aAAa,EAAE;YACnB,aAAa,GAAG,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;YACvD,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC;YAClD,MAAM,aAAa,CAAC;YACpB,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,yBAAyB;SAChE;QACD,MAAM,aAAa,GAAG,MAAM,aAAa,CAAC;QAC1C,MAAM,IAAI,GAAkB,aAAa,CAAC,MAAM,EAAE,CAAC;QACnD,IAAA,2BAAmB,EAAC,IAAI,CAAC,CAAC;QAC1B,IAAI,IAAI,CAAC,KAAK,EAAE;YACf,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;YACrC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE;gBAChC,sBAAsB;gBACtB,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,iBAAiB,CAAC,MAAM,IAAI,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC;aAC1E;SACD;QACD,OAAO,IAAI,CAAC;IACb,CAAC;CACD;AApJD,sCAoJC","sourcesContent":["import {assertWeatherDataV2, CountryCode, LangCode, Loadable, WeatherDataV2} from './types';\nimport {Err, Ok, Result, safeAsyncResult, safeAsyncResultBuilder} from 'mharj-result';\nimport {fetchErrorWrapper} from './lib/fetchUtils';\nimport type {ICacheOrAsync} from '@avanio/expire-cache';\nimport type {IOpenWeatherV2} from './interfaces/IOpenWeatherV2';\n\nconst fetchResult = safeAsyncResultBuilder<Parameters<typeof fetch>, Response, SyntaxError | TypeError>(fetch);\n\nfunction isJson(response: Response): boolean {\n\tconst contentType = response.headers.get('content-type');\n\treturn (contentType && contentType.startsWith('application/json')) || false;\n}\n\nfunction isOpenWeatherError(data: unknown): data is {cod: string; message: string} {\n\treturn typeof data === 'object' && data !== null && 'cod' in data && 'message' in data;\n}\n\n/**\n * Open Weather V2 API Common Options\n * @default {lang: 'en', units: 'standard'} in API\n * @example\n * {lang: 'fi', units: 'metric'}\n */\nexport type OpenWeatherV2CommonOptions = {\n\t/**\n\t * Language code\n\t */\n\tlang?: LangCode;\n\t/**\n\t * Weather units\n\t */\n\tunits?: 'standard' | 'metric' | 'imperial';\n};\n\nconst basePath = 'https://api.openweathermap.org/data/2.5/weather';\n\nfunction buildUrl(params: URLSearchParams): string {\n\treturn `${basePath}?${params.toString()}`;\n}\n\nfunction buildLogUrl(params: URLSearchParams): string {\n\tconst logParams = new URLSearchParams(params);\n\tlogParams.set('appid', '***');\n\treturn buildUrl(logParams);\n}\n\nconst defaultImplementation: IOpenWeatherV2 = {\n\tdataWeatherApi: async (params: URLSearchParams): Promise<Result<WeatherDataV2, SyntaxError | TypeError>> => {\n\t\tconst logUrl = buildLogUrl(params);\n\t\tconst result = await fetchResult(buildUrl(params));\n\t\tif (!result.isOk) {\n\t\t\treturn Err(result.err());\n\t\t}\n\t\tconst res = result.ok();\n\t\tif (!res.ok) {\n\t\t\tif (isJson(res)) {\n\t\t\t\tconst data: unknown = await res.json();\n\t\t\t\tif (isOpenWeatherError(data)) {\n\t\t\t\t\treturn Err(new TypeError(`OpenWeatherV2 error: ${data.message} from ${logUrl}`));\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn Err(new TypeError(`OpenWeatherV2 http error: ${res.status} ${res.statusText} from ${logUrl}`));\n\t\t}\n\t\tif (!isJson(res)) {\n\t\t\treturn Err(new TypeError(`OpenWeatherV2 response is not json payload from ${logUrl}`));\n\t\t}\n\t\tconst jsonResult = await safeAsyncResult<unknown, SyntaxError>(res.json());\n\t\tif (!jsonResult.isOk) {\n\t\t\treturn Err(jsonResult.err());\n\t\t}\n\t\tconst data = jsonResult.ok();\n\t\tassertWeatherDataV2(data);\n\t\treturn Ok<WeatherDataV2, SyntaxError | TypeError>(data);\n\t},\n};\n\n/**\n * Open Weather V2 API\n * @example\n * const weather = new OpenWeatherV2('your-api-key');\n *\n * const cache = new ExpireCache<WeatherDataV2>(undefined, undefined, 900000); // data 15 minutes in cache\n * const weather = new OpenWeatherV2(() => Promise.resolve('your-api-key'), cache);\n *\n * const data: WeatherDataV2 = (await weather.getWeatherById(2643743)).unwrap(); // throws if error\n * const data: WeatherDataV2 | undefined = (await weather.getWeatherByCity('Helsinki', 'fi')).ok();\n *\n * const result: Result<WeatherDataV2> = await weather.getWeatherByLatLon(60.1699, 24.9384);\n * result.match({\n * Ok: (data: WeatherDataV2) => console.log(data),\n * Err: (err: DOMException | TypeError) => console.error(err),\n * });\n *\n * if(result.isOk) {\n * const data: WeatherDataV2 = data.ok();\n * } else {\n * const err: DOMException | TypeError = data.err();\n * }\n */\nexport class OpenWeatherV2 {\n\tprivate cache: ICacheOrAsync<WeatherDataV2> | undefined;\n\tprivate loadableApiKey: Loadable<string>;\n\tprivate apiHandler: IOpenWeatherV2;\n\tprivate fetchPromiseMap = new Map<string, Promise<Result<WeatherDataV2, DOMException | TypeError>>>();\n\t/**\n\t * OpenWeatherV2 constructor\n\t * @param {Loadable<string>} loadableApiKey - Loadable API key\n\t * @param {ICacheOrAsync<WeatherDataV2>=} cache - optional async cache implementation\n\t * @param {IOpenWeatherV2=} apiHandler - optional API handler implementation for mocking\n\t */\n\tconstructor(loadableApiKey: Loadable<string>, cache?: ICacheOrAsync<WeatherDataV2>, apiHandler: IOpenWeatherV2 = defaultImplementation) {\n\t\tthis.loadableApiKey = loadableApiKey;\n\t\tthis.cache = cache;\n\t\tthis.apiHandler = apiHandler;\n\t}\n\n\t/**\n\t * get weather by Id\n\t * @param {number} id - Weather station ID\n\t * @param {OpenWeatherV2CommonOptions=} opts - Common options, example ```{lang: 'fi', units: 'metric'}```, defaults ```{lang: 'en', units: 'standard'}```\n\t * @return {Promise<Result<WeatherDataV2, DOMException | TypeError>>} Weather data Result Promise\n\t * @example\n\t * const result: Result<WeatherDataV2, DOMException | TypeError> = await weather.getWeatherResultById(id: 564, {lang: 'fi'});\n\t * if (result.isOk) {\n\t * const weatherData: WeatherDataV2 = result.ok();\n\t * } else {\n\t * const error: DOMException | TypeError = result.err();\n\t * }\n\t */\n\tpublic async getWeatherById(id: number, opts: OpenWeatherV2CommonOptions = {}): Promise<Result<WeatherDataV2, DOMException | TypeError>> {\n\t\ttry {\n\t\t\tconst cacheKey = this.buildBaseCacheKey(`id:${id}`, opts);\n\t\t\tlet cacheEntry = this.cache && (await this.cache.get(cacheKey));\n\t\t\tif (!cacheEntry) {\n\t\t\t\tconst params = await this.buildBaseParams(opts);\n\t\t\t\tparams.append('id', String(id));\n\t\t\t\tcacheEntry = await this.handleFetch(cacheKey, params, opts);\n\t\t\t}\n\t\t\treturn Ok(cacheEntry);\n\t\t} catch (err) {\n\t\t\treturn Err(fetchErrorWrapper(err));\n\t\t}\n\t}\n\n\t/**\n\t * get weather with city name and optional country code\n\t * @param {string} city - City name\n\t * @param {countryCode=} countryCode - Optional Country code\n\t * @param {OpenWeatherV2CommonOptions=} opts - Common options, example ```{lang: 'fi', units: 'metric'}```, defaults ```{lang: 'en', units: 'standard'}```\n\t * @return {Promise<Result<WeatherDataV2, DOMException | TypeError>>} Weather data Result Promise\n\t * @example\n\t * const result: Result<WeatherDataV2, DOMException | TypeError> = await weather.getWeatherByCity('Helsinki', 'fi', {lang: 'fi'});\n\t * if (result.isOk) {\n\t * const weatherData: WeatherDataV2 = result.ok();\n\t * } else {\n\t * const error: DOMException | TypeError = result.err();\n\t * }\n\t */\n\tpublic async getWeatherByCity(\n\t\tcity: string,\n\t\tcountryCode?: CountryCode,\n\t\topts: OpenWeatherV2CommonOptions = {},\n\t): Promise<Result<WeatherDataV2, DOMException | TypeError>> {\n\t\ttry {\n\t\t\tconst cacheKey = this.buildBaseCacheKey(`q:${city}:${countryCode}`, opts);\n\t\t\tlet cacheEntry = this.cache && (await this.cache.get(cacheKey));\n\t\t\tif (!cacheEntry) {\n\t\t\t\tconst params = await this.buildBaseParams(opts);\n\t\t\t\tparams.append('q', countryCode ? `${city},${countryCode}` : city);\n\t\t\t\tcacheEntry = await this.handleFetch(cacheKey, params, opts);\n\t\t\t}\n\t\t\treturn Ok(cacheEntry);\n\t\t} catch (err) {\n\t\t\treturn Err(fetchErrorWrapper(err));\n\t\t}\n\t}\n\n\t/**\n\t * get weather with latitude and longitude with Result\n\t * @param {number} lat - Latitude\n\t * @param {number} lon - Longitude\n\t * @param {OpenWeatherV2CommonOptions=} opts - Common options, example ```{lang: 'fi', units: 'metric'}```, defaults ```{lang: 'en', units: 'standard'}```\n\t * @return {Promise<Result<WeatherDataV2, DOMException | TypeError>>} Weather data Result Promise\n\t * @example\n\t * const result: Result<WeatherDataV2, DOMException | TypeError> = await weather.getWeatherByLatLon(60.1699, 24.9384, {lang: 'fi'});\n\t * if (result.isOk) {\n\t * const weatherData: WeatherDataV2 = result.ok();\n\t * } else {\n\t * const error: DOMException | TypeError = result.err();\n\t * }\n\t */\n\tpublic async getWeatherByLatLon(lat: number, lon: number, opts: OpenWeatherV2CommonOptions = {}): Promise<Result<WeatherDataV2, DOMException | TypeError>> {\n\t\ttry {\n\t\t\tconst cacheKey = this.buildBaseCacheKey(`latlon:${lat}:${lon}`, opts);\n\t\t\tlet cacheEntry = this.cache && (await this.cache.get(cacheKey));\n\t\t\tif (!cacheEntry) {\n\t\t\t\tconst params = await this.buildBaseParams(opts);\n\t\t\t\tparams.append('lat', String(lat));\n\t\t\t\tparams.append('lon', String(lon));\n\t\t\t\tcacheEntry = await this.handleFetch(cacheKey, params, opts);\n\t\t\t}\n\t\t\treturn Ok(cacheEntry);\n\t\t} catch (err) {\n\t\t\treturn Err(fetchErrorWrapper(err));\n\t\t}\n\t}\n\n\tprivate async buildBaseParams({lang, units}: OpenWeatherV2CommonOptions): Promise<URLSearchParams> {\n\t\tconst apiKey = await (typeof this.loadableApiKey === 'function' ? this.loadableApiKey() : this.loadableApiKey);\n\t\tconst params = new URLSearchParams();\n\t\tlang && params.append('lang', lang);\n\t\tunits && params.append('units', units);\n\t\tparams.append('appid', apiKey);\n\t\treturn params;\n\t}\n\n\t/**\n\t * build base cache key\n\t * @param main - main cache key prefix\n\t * @param opts - OpenWeatherV2CommonOptions\n\t * @returns {CacheKey}\n\t */\n\tprivate buildBaseCacheKey(main: string, {lang, units}: OpenWeatherV2CommonOptions): string {\n\t\treturn `${main}:${lang}:${units}`;\n\t}\n\n\tprivate async handleFetch(cacheKey: string, params: URLSearchParams, opts: OpenWeatherV2CommonOptions): Promise<WeatherDataV2> {\n\t\t// allow only one fetch per cacheKey until it is resolved\n\t\tlet promiseResult = this.fetchPromiseMap.get(cacheKey);\n\t\tif (!promiseResult) {\n\t\t\tpromiseResult = this.apiHandler.dataWeatherApi(params);\n\t\t\tthis.fetchPromiseMap.set(cacheKey, promiseResult);\n\t\t\tawait promiseResult;\n\t\t\tthis.fetchPromiseMap.delete(cacheKey); // clear promise from map\n\t\t}\n\t\tconst dataApiResult = await promiseResult;\n\t\tconst data: WeatherDataV2 = dataApiResult.unwrap();\n\t\tassertWeatherDataV2(data);\n\t\tif (this.cache) {\n\t\t\tawait this.cache.set(cacheKey, data);\n\t\t\tif (!cacheKey.startsWith('id:')) {\n\t\t\t\t// update id cache too\n\t\t\t\tawait this.cache.set(this.buildBaseCacheKey(`id:${data.id}`, opts), data);\n\t\t\t}\n\t\t}\n\t\treturn data;\n\t}\n}\n"]}
1
+ {"version":3,"file":"OpenWeatherV2.js","sourceRoot":"./src/","sources":["OpenWeatherV2.ts"],"names":[],"mappings":";;;AAAA,mCAA4F;AAC5F,8DAAoG;AACpG,iDAAmD;AAInD,MAAM,WAAW,GAAG,IAAA,sCAAsB,EAA8D,KAAK,CAAC,CAAC;AAE/G,SAAS,MAAM,CAAC,Q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IAAI,IAAI,CAAC,KAAK,EAAE;YACf,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;YACrC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE;gBAChC,sBAAsB;gBACtB,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,iBAAiB,CAAC,MAAM,IAAI,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC;aAC1E;SACD;QACD,OAAO,IAAI,CAAC;IACb,CAAC;CACD;AApJD,sCAoJC","sourcesContent":["import {assertWeatherDataV2, CountryCode, LangCode, Loadable, WeatherDataV2} from './types';\nimport {Err, Ok, Result, safeAsyncResult, safeAsyncResultBuilder} from '@luolapeikko/result-option';\nimport {fetchErrorWrapper} from './lib/fetchUtils';\nimport type {ICacheOrAsync} from '@avanio/expire-cache';\nimport type {IOpenWeatherV2} from './interfaces/IOpenWeatherV2';\n\nconst fetchResult = safeAsyncResultBuilder<Parameters<typeof fetch>, Response, SyntaxError | TypeError>(fetch);\n\nfunction isJson(response: Response): boolean {\n\tconst contentType = response.headers.get('content-type');\n\treturn (contentType && contentType.startsWith('application/json')) || false;\n}\n\nfunction isOpenWeatherError(data: unknown): data is {cod: string; message: string} {\n\treturn typeof data === 'object' && data !== null && 'cod' in data && 'message' in data;\n}\n\n/**\n * Open Weather V2 API Common Options\n * @default {lang: 'en', units: 'standard'} in API\n * @example\n * {lang: 'fi', units: 'metric'}\n */\nexport type OpenWeatherV2CommonOptions = {\n\t/**\n\t * Language code\n\t */\n\tlang?: LangCode;\n\t/**\n\t * Weather units\n\t */\n\tunits?: 'standard' | 'metric' | 'imperial';\n};\n\nconst basePath = 'https://api.openweathermap.org/data/2.5/weather';\n\nfunction buildUrl(params: URLSearchParams): string {\n\treturn `${basePath}?${params.toString()}`;\n}\n\nfunction buildLogUrl(params: URLSearchParams): string {\n\tconst logParams = new URLSearchParams(params);\n\tlogParams.set('appid', '***');\n\treturn buildUrl(logParams);\n}\n\nconst defaultImplementation: IOpenWeatherV2 = {\n\tdataWeatherApi: async (params: URLSearchParams): Promise<Result<WeatherDataV2, SyntaxError | TypeError>> => {\n\t\tconst logUrl = buildLogUrl(params);\n\t\tconst result = await fetchResult(buildUrl(params));\n\t\tif (!result.isOk) {\n\t\t\treturn Err(result.err());\n\t\t}\n\t\tconst res = result.ok();\n\t\tif (!res.ok) {\n\t\t\tif (isJson(res)) {\n\t\t\t\tconst data: unknown = await res.json();\n\t\t\t\tif (isOpenWeatherError(data)) {\n\t\t\t\t\treturn Err(new TypeError(`OpenWeatherV2 error: ${data.message} from ${logUrl}`));\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn Err(new TypeError(`OpenWeatherV2 http error: ${res.status} ${res.statusText} from ${logUrl}`));\n\t\t}\n\t\tif (!isJson(res)) {\n\t\t\treturn Err(new TypeError(`OpenWeatherV2 response is not json payload from ${logUrl}`));\n\t\t}\n\t\tconst jsonResult = await safeAsyncResult<unknown, SyntaxError>(res.json());\n\t\tif (!jsonResult.isOk) {\n\t\t\treturn Err(jsonResult.err());\n\t\t}\n\t\tconst data = jsonResult.ok();\n\t\tassertWeatherDataV2(data);\n\t\treturn Ok<WeatherDataV2, SyntaxError | TypeError>(data);\n\t},\n};\n\n/**\n * Open Weather V2 API\n * @example\n * const weather = new OpenWeatherV2('your-api-key');\n *\n * const cache = new ExpireCache<WeatherDataV2>(undefined, undefined, 900000); // data 15 minutes in cache\n * const weather = new OpenWeatherV2(() => Promise.resolve('your-api-key'), cache);\n *\n * const data: WeatherDataV2 = (await weather.getWeatherById(2643743)).unwrap(); // throws if error\n * const data: WeatherDataV2 | undefined = (await weather.getWeatherByCity('Helsinki', 'fi')).ok();\n *\n * const result: Result<WeatherDataV2> = await weather.getWeatherByLatLon(60.1699, 24.9384);\n * result.match({\n * Ok: (data: WeatherDataV2) => console.log(data),\n * Err: (err: DOMException | TypeError) => console.error(err),\n * });\n *\n * if(result.isOk) {\n * const data: WeatherDataV2 = data.ok();\n * } else {\n * const err: DOMException | TypeError = data.err();\n * }\n */\nexport class OpenWeatherV2 {\n\tprivate cache: ICacheOrAsync<WeatherDataV2> | undefined;\n\tprivate loadableApiKey: Loadable<string>;\n\tprivate apiHandler: IOpenWeatherV2;\n\tprivate fetchPromiseMap = new Map<string, Promise<Result<WeatherDataV2, DOMException | TypeError>>>();\n\t/**\n\t * OpenWeatherV2 constructor\n\t * @param {Loadable<string>} loadableApiKey - Loadable API key\n\t * @param {ICacheOrAsync<WeatherDataV2>=} cache - optional async cache implementation\n\t * @param {IOpenWeatherV2=} apiHandler - optional API handler implementation for mocking\n\t */\n\tconstructor(loadableApiKey: Loadable<string>, cache?: ICacheOrAsync<WeatherDataV2>, apiHandler: IOpenWeatherV2 = defaultImplementation) {\n\t\tthis.loadableApiKey = loadableApiKey;\n\t\tthis.cache = cache;\n\t\tthis.apiHandler = apiHandler;\n\t}\n\n\t/**\n\t * get weather by Id\n\t * @param {number} id - Weather station ID\n\t * @param {OpenWeatherV2CommonOptions=} opts - Common options, example ```{lang: 'fi', units: 'metric'}```, defaults ```{lang: 'en', units: 'standard'}```\n\t * @return {Promise<Result<WeatherDataV2, DOMException | TypeError>>} Weather data Result Promise\n\t * @example\n\t * const result: Result<WeatherDataV2, DOMException | TypeError> = await weather.getWeatherResultById(id: 564, {lang: 'fi'});\n\t * if (result.isOk) {\n\t * const weatherData: WeatherDataV2 = result.ok();\n\t * } else {\n\t * const error: DOMException | TypeError = result.err();\n\t * }\n\t */\n\tpublic async getWeatherById(id: number, opts: OpenWeatherV2CommonOptions = {}): Promise<Result<WeatherDataV2, DOMException | TypeError>> {\n\t\ttry {\n\t\t\tconst cacheKey = this.buildBaseCacheKey(`id:${id}`, opts);\n\t\t\tlet cacheEntry = this.cache && (await this.cache.get(cacheKey));\n\t\t\tif (!cacheEntry) {\n\t\t\t\tconst params = await this.buildBaseParams(opts);\n\t\t\t\tparams.append('id', String(id));\n\t\t\t\tcacheEntry = await this.handleFetch(cacheKey, params, opts);\n\t\t\t}\n\t\t\treturn Ok(cacheEntry);\n\t\t} catch (err) {\n\t\t\treturn Err(fetchErrorWrapper(err));\n\t\t}\n\t}\n\n\t/**\n\t * get weather with city name and optional country code\n\t * @param {string} city - City name\n\t * @param {countryCode=} countryCode - Optional Country code\n\t * @param {OpenWeatherV2CommonOptions=} opts - Common options, example ```{lang: 'fi', units: 'metric'}```, defaults ```{lang: 'en', units: 'standard'}```\n\t * @return {Promise<Result<WeatherDataV2, DOMException | TypeError>>} Weather data Result Promise\n\t * @example\n\t * const result: Result<WeatherDataV2, DOMException | TypeError> = await weather.getWeatherByCity('Helsinki', 'fi', {lang: 'fi'});\n\t * if (result.isOk) {\n\t * const weatherData: WeatherDataV2 = result.ok();\n\t * } else {\n\t * const error: DOMException | TypeError = result.err();\n\t * }\n\t */\n\tpublic async getWeatherByCity(\n\t\tcity: string,\n\t\tcountryCode?: CountryCode,\n\t\topts: OpenWeatherV2CommonOptions = {},\n\t): Promise<Result<WeatherDataV2, DOMException | TypeError>> {\n\t\ttry {\n\t\t\tconst cacheKey = this.buildBaseCacheKey(`q:${city}:${countryCode}`, opts);\n\t\t\tlet cacheEntry = this.cache && (await this.cache.get(cacheKey));\n\t\t\tif (!cacheEntry) {\n\t\t\t\tconst params = await this.buildBaseParams(opts);\n\t\t\t\tparams.append('q', countryCode ? `${city},${countryCode}` : city);\n\t\t\t\tcacheEntry = await this.handleFetch(cacheKey, params, opts);\n\t\t\t}\n\t\t\treturn Ok(cacheEntry);\n\t\t} catch (err) {\n\t\t\treturn Err(fetchErrorWrapper(err));\n\t\t}\n\t}\n\n\t/**\n\t * get weather with latitude and longitude with Result\n\t * @param {number} lat - Latitude\n\t * @param {number} lon - Longitude\n\t * @param {OpenWeatherV2CommonOptions=} opts - Common options, example ```{lang: 'fi', units: 'metric'}```, defaults ```{lang: 'en', units: 'standard'}```\n\t * @return {Promise<Result<WeatherDataV2, DOMException | TypeError>>} Weather data Result Promise\n\t * @example\n\t * const result: Result<WeatherDataV2, DOMException | TypeError> = await weather.getWeatherByLatLon(60.1699, 24.9384, {lang: 'fi'});\n\t * if (result.isOk) {\n\t * const weatherData: WeatherDataV2 = result.ok();\n\t * } else {\n\t * const error: DOMException | TypeError = result.err();\n\t * }\n\t */\n\tpublic async getWeatherByLatLon(lat: number, lon: number, opts: OpenWeatherV2CommonOptions = {}): Promise<Result<WeatherDataV2, DOMException | TypeError>> {\n\t\ttry {\n\t\t\tconst cacheKey = this.buildBaseCacheKey(`latlon:${lat}:${lon}`, opts);\n\t\t\tlet cacheEntry = this.cache && (await this.cache.get(cacheKey));\n\t\t\tif (!cacheEntry) {\n\t\t\t\tconst params = await this.buildBaseParams(opts);\n\t\t\t\tparams.append('lat', String(lat));\n\t\t\t\tparams.append('lon', String(lon));\n\t\t\t\tcacheEntry = await this.handleFetch(cacheKey, params, opts);\n\t\t\t}\n\t\t\treturn Ok(cacheEntry);\n\t\t} catch (err) {\n\t\t\treturn Err(fetchErrorWrapper(err));\n\t\t}\n\t}\n\n\tprivate async buildBaseParams({lang, units}: OpenWeatherV2CommonOptions): Promise<URLSearchParams> {\n\t\tconst apiKey = await (typeof this.loadableApiKey === 'function' ? this.loadableApiKey() : this.loadableApiKey);\n\t\tconst params = new URLSearchParams();\n\t\tlang && params.append('lang', lang);\n\t\tunits && params.append('units', units);\n\t\tparams.append('appid', apiKey);\n\t\treturn params;\n\t}\n\n\t/**\n\t * build base cache key\n\t * @param main - main cache key prefix\n\t * @param opts - OpenWeatherV2CommonOptions\n\t * @returns {CacheKey}\n\t */\n\tprivate buildBaseCacheKey(main: string, {lang, units}: OpenWeatherV2CommonOptions): string {\n\t\treturn `${main}:${lang}:${units}`;\n\t}\n\n\tprivate async handleFetch(cacheKey: string, params: URLSearchParams, opts: OpenWeatherV2CommonOptions): Promise<WeatherDataV2> {\n\t\t// allow only one fetch per cacheKey until it is resolved\n\t\tlet promiseResult = this.fetchPromiseMap.get(cacheKey);\n\t\tif (!promiseResult) {\n\t\t\tpromiseResult = this.apiHandler.dataWeatherApi(params);\n\t\t\tthis.fetchPromiseMap.set(cacheKey, promiseResult);\n\t\t\tawait promiseResult;\n\t\t\tthis.fetchPromiseMap.delete(cacheKey); // clear promise from map\n\t\t}\n\t\tconst dataApiResult = await promiseResult;\n\t\tconst data: WeatherDataV2 = dataApiResult.unwrap();\n\t\tassertWeatherDataV2(data);\n\t\tif (this.cache) {\n\t\t\tawait this.cache.set(cacheKey, data);\n\t\t\tif (!cacheKey.startsWith('id:')) {\n\t\t\t\t// update id cache too\n\t\t\t\tawait this.cache.set(this.buildBaseCacheKey(`id:${data.id}`, opts), data);\n\t\t\t}\n\t\t}\n\t\treturn data;\n\t}\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { Result } from 'mharj-result';
1
+ import { Result } from '@luolapeikko/result-option';
2
2
  import { WeatherDataV2 } from '../types/v2';
3
3
  /**
4
4
  * Interface for OpenWeatherMap API v2 implementation.
@@ -1 +1 @@
1
- {"version":3,"file":"IOpenWeatherV2.js","sourceRoot":"./src/","sources":["interfaces/IOpenWeatherV2.ts"],"names":[],"mappings":"","sourcesContent":["import {Result} from 'mharj-result';\nimport {WeatherDataV2} from '../types/v2';\n\n/**\n * Interface for OpenWeatherMap API v2 implementation.\n */\nexport interface IOpenWeatherV2 {\n\tdataWeatherApi: (params: URLSearchParams) => Promise<Result<WeatherDataV2, SyntaxError | TypeError>>;\n}\n"]}
1
+ {"version":3,"file":"IOpenWeatherV2.js","sourceRoot":"./src/","sources":["interfaces/IOpenWeatherV2.ts"],"names":[],"mappings":"","sourcesContent":["import {Result} from '@luolapeikko/result-option';\nimport {WeatherDataV2} from '../types/v2';\n\n/**\n * Interface for OpenWeatherMap API v2 implementation.\n */\nexport interface IOpenWeatherV2 {\n\tdataWeatherApi: (params: URLSearchParams) => Promise<Result<WeatherDataV2, SyntaxError | TypeError>>;\n}\n"]}
@@ -84,16 +84,16 @@ export declare const weatherDataV2Schema: z.ZodObject<{
84
84
  country: string;
85
85
  sunrise: number;
86
86
  sunset: number;
87
- id?: number | undefined;
88
- message?: number | undefined;
89
87
  type?: number | undefined;
88
+ message?: number | undefined;
89
+ id?: number | undefined;
90
90
  }, {
91
91
  country: string;
92
92
  sunrise: number;
93
93
  sunset: number;
94
- id?: number | undefined;
95
- message?: number | undefined;
96
94
  type?: number | undefined;
95
+ message?: number | undefined;
96
+ id?: number | undefined;
97
97
  }>;
98
98
  timezone: z.ZodNumber;
99
99
  visibility: z.ZodNumber;
@@ -150,9 +150,9 @@ export declare const weatherDataV2Schema: z.ZodObject<{
150
150
  country: string;
151
151
  sunrise: number;
152
152
  sunset: number;
153
- id?: number | undefined;
154
- message?: number | undefined;
155
153
  type?: number | undefined;
154
+ message?: number | undefined;
155
+ id?: number | undefined;
156
156
  };
157
157
  timezone: number;
158
158
  weather: {
@@ -200,9 +200,9 @@ export declare const weatherDataV2Schema: z.ZodObject<{
200
200
  country: string;
201
201
  sunrise: number;
202
202
  sunset: number;
203
- id?: number | undefined;
204
- message?: number | undefined;
205
203
  type?: number | undefined;
204
+ message?: number | undefined;
205
+ id?: number | undefined;
206
206
  };
207
207
  timezone: number;
208
208
  weather: {
@@ -1,4 +1,4 @@
1
- import { Option } from 'mharj-result';
1
+ import { Option } from '@luolapeikko/result-option';
2
2
  import { z } from 'zod';
3
3
  /**
4
4
  * This is a list of weather ids, groups and descriptions from OpenWeatherMap API
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getWeatherV2Description = exports.weatherIdSchema = exports.weatherIdGroup = void 0;
4
- const mharj_result_1 = require("mharj-result");
4
+ const result_option_1 = require("@luolapeikko/result-option");
5
5
  const zod_1 = require("zod");
6
6
  /**
7
7
  * This is a list of weather ids, groups and descriptions from OpenWeatherMap API
@@ -311,7 +311,7 @@ exports.weatherIdSchema = zod_1.z.custom((val) => {
311
311
  * }
312
312
  */
313
313
  function getWeatherV2Description(id) {
314
- return (0, mharj_result_1.undefinedOptionWrap)(exports.weatherIdGroup.find((x) => x.id === id)?.description);
314
+ return (0, result_option_1.undefinedOptionWrap)(exports.weatherIdGroup.find((x) => x.id === id)?.description);
315
315
  }
316
316
  exports.getWeatherV2Description = getWeatherV2Description;
317
317
  //# sourceMappingURL=weatherIdGroup.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"weatherIdGroup.js","sourceRoot":"./src/","sources":["types/v2/weatherIdGroup.ts"],"names":[],"mappings":";;;AAAA,+CAAyD;AACzD,6BAAsB;AAEtB;;GAEG;AACU,QAAA,cAAc,GAAG;IAC7B;QACC,EAAE,EAAE,GAAG;QACP,KAAK,EAAE,cAAc;QACrB,WAAW,EAAE,8BAA8B;KAC3C;IACD;QACC,EAAE,EAAE,GAAG;QACP,KAAK,EAAE,cAAc;QACrB,WAAW,EAAE,wBAAwB;KACrC;IACD;QACC,EAAE,EAAE,GAAG;QACP,KAAK,EAAE,cAAc;QACrB,WAAW,EAAE,8BAA8B;KAC3C;IACD;QACC,EAAE,EAAE,GAAG;QACP,KAAK,EAAE,cAAc;QACrB,WAAW,EAAE,oBAAoB;KACjC;IACD;QACC,EAAE,EAAE,GAAG;QACP,KAAK,EAAE,cAAc;QACrB,WAAW,EAAE,cAAc;KAC3B;IACD;QACC,EAAE,EAAE,GAAG;QACP,KAAK,EAAE,cAAc;QACrB,WAAW,EAAE,oBAAoB;KACjC;IACD;QACC,EAAE,EAAE,GAAG;QACP,KAAK,EAAE,cAAc;QACrB,WAAW,EAAE,qBAAqB;KAClC;IACD;QACC,EAAE,EAAE,GAAG;QACP,KAAK,EAAE,cAAc;QACrB,WAAW,EAAE,iCAAiC;KAC9C;IACD;QACC,EAAE,EAAE,GAAG;QACP,KAAK,EAAE,cAAc;QACrB,WAAW,EAAE,2BAA2B;KACxC;IACD;QACC,EAAE,EAAE,GAAG;QACP,KAAK,EAAE,cAAc;QACrB,WAAW,EAAE,iCAAiC;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AqBX;;;GAGG;AACU,QAAA,eAAe,GAAG,OAAC,CAAC,MAAM,CAAY,CAAC,GAAG,EAAE,EAAE;IAC1D,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;QAC5B,OAAO,EAAC,OAAO,EAAE,mBAAmB,EAAE,OAAO,EAAE,KAAK,EAAC,CAAC;KACtD;IACD,IAAI,CAAC,sBAAc,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,GAAG,CAAC,EAAE;QAC9C,OAAO,EAAC,OAAO,EAAE,6BAA6B,EAAE,OAAO,EAAE,KAAK,EAAC,CAAC;KAChE;IACD,OAAO,GAAG,CAAC;AACZ,CAAC,CAAC,CAAC;AAEH;;;;;;;;;;;;;GAaG;AACH,SAAgB,uBAAuB,CAAC,EAAyB;IAChE,OAAO,IAAA,kCAAmB,EAAC,sBAAc,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,WAAW,CAAC,CAAC;AAClF,CAAC;AAFD,0DAEC","sourcesContent":["import {Option, undefinedOptionWrap} from 'mharj-result';\nimport {z} from 'zod';\n\n/**\n * This is a list of weather ids, groups and descriptions from OpenWeatherMap API\n */\nexport const weatherIdGroup = [\n\t{\n\t\tid: 200,\n\t\tgroup: 'thunderstorm',\n\t\tdescription: 'thunderstorm_with_light_rain',\n\t},\n\t{\n\t\tid: 201,\n\t\tgroup: 'thunderstorm',\n\t\tdescription: 'thunderstorm_with_rain',\n\t},\n\t{\n\t\tid: 202,\n\t\tgroup: 'thunderstorm',\n\t\tdescription: 'thunderstorm_with_heavy_rain',\n\t},\n\t{\n\t\tid: 210,\n\t\tgroup: 'thunderstorm',\n\t\tdescription: 'light_thunderstorm',\n\t},\n\t{\n\t\tid: 211,\n\t\tgroup: 'thunderstorm',\n\t\tdescription: 'thunderstorm',\n\t},\n\t{\n\t\tid: 212,\n\t\tgroup: 'thunderstorm',\n\t\tdescription: 'heavy_thunderstorm',\n\t},\n\t{\n\t\tid: 221,\n\t\tgroup: 'thunderstorm',\n\t\tdescription: 'ragged_thunderstorm',\n\t},\n\t{\n\t\tid: 230,\n\t\tgroup: 'thunderstorm',\n\t\tdescription: 'thunderstorm_with_light_drizzle',\n\t},\n\t{\n\t\tid: 231,\n\t\tgroup: 'thunderstorm',\n\t\tdescription: 'thunderstorm_with_drizzle',\n\t},\n\t{\n\t\tid: 232,\n\t\tgroup: 'thunderstorm',\n\t\tdescription: 'thunderstorm_with_heavy_drizzle',\n\t},\n\t{\n\t\tid: 300,\n\t\tgroup: 'drizzle',\n\t\tdescription: 'light_intensity_drizzle',\n\t},\n\t{\n\t\tid: 301,\n\t\tgroup: 'drizzle',\n\t\tdescription: 'drizzle',\n\t},\n\t{\n\t\tid: 302,\n\t\tgroup: 'drizzle',\n\t\tdescription: 'heavy_intensity_drizzle',\n\t},\n\t{\n\t\tid: 310,\n\t\tgroup: 'drizzle',\n\t\tdescription: 'light_intensity_drizzle_rain',\n\t},\n\t{\n\t\tid: 311,\n\t\tgroup: 'drizzle',\n\t\tdescription: 'drizzle_rain',\n\t},\n\t{\n\t\tid: 312,\n\t\tgroup: 'drizzle',\n\t\tdescription: 'heavy_intensity_drizzle_rain',\n\t},\n\t{\n\t\tid: 313,\n\t\tgroup: 'drizzle',\n\t\tdescription: 'shower_rain_and_drizzle',\n\t},\n\t{\n\t\tid: 314,\n\t\tgroup: 'drizzle',\n\t\tdescription: 'heavy_shower_rain_and_drizzle',\n\t},\n\t{\n\t\tid: 321,\n\t\tgroup: 'drizzle',\n\t\tdescription: 'shower_drizzle',\n\t},\n\t{\n\t\tid: 500,\n\t\tgroup: 'rain',\n\t\tdescription: 'light_rain',\n\t},\n\t{\n\t\tid: 501,\n\t\tgroup: 'rain',\n\t\tdescription: 'moderate_rain',\n\t},\n\t{\n\t\tid: 502,\n\t\tgroup: 'rain',\n\t\tdescription: 'heavy_intensity_rain',\n\t},\n\t{\n\t\tid: 503,\n\t\tgroup: 'rain',\n\t\tdescription: 'very_heavy_rain',\n\t},\n\t{\n\t\tid: 504,\n\t\tgroup: 'rain',\n\t\tdescription: 'extreme_rain',\n\t},\n\t{\n\t\tid: 511,\n\t\tgroup: 'rain',\n\t\tdescription: 'freezing_rain',\n\t},\n\t{\n\t\tid: 520,\n\t\tgroup: 'rain',\n\t\tdescription: 'light_intensity_shower_rain',\n\t},\n\t{\n\t\tid: 521,\n\t\tgroup: 'rain',\n\t\tdescription: 'shower_rain',\n\t},\n\t{\n\t\tid: 522,\n\t\tgroup: 'rain',\n\t\tdescription: 'heavy_intensity_shower_rain',\n\t},\n\t{\n\t\tid: 531,\n\t\tgroup: 'rain',\n\t\tdescription: 'ragged_shower_rain',\n\t},\n\t{\n\t\tid: 600,\n\t\tgroup: 'snow',\n\t\tdescription: 'light_snow',\n\t},\n\t{\n\t\tid: 601,\n\t\tgroup: 'snow',\n\t\tdescription: 'snow',\n\t},\n\t{\n\t\tid: 602,\n\t\tgroup: 'snow',\n\t\tdescription: 'heavy_snow',\n\t},\n\t{\n\t\tid: 611,\n\t\tgroup: 'snow',\n\t\tdescription: 'sleet',\n\t},\n\t{\n\t\tid: 612,\n\t\tgroup: 'snow',\n\t\tdescription: 'light_shower_sleet',\n\t},\n\t{\n\t\tid: 613,\n\t\tgroup: 'snow',\n\t\tdescription: 'shower_sleet',\n\t},\n\t{\n\t\tid: 615,\n\t\tgroup: 'snow',\n\t\tdescription: 'light_rain_and_snow',\n\t},\n\t{\n\t\tid: 616,\n\t\tgroup: 'snow',\n\t\tdescription: 'rain_and_snow',\n\t},\n\t{\n\t\tid: 620,\n\t\tgroup: 'snow',\n\t\tdescription: 'light_shower_snow',\n\t},\n\t{\n\t\tid: 621,\n\t\tgroup: 'snow',\n\t\tdescription: 'shower_snow',\n\t},\n\t{\n\t\tid: 622,\n\t\tgroup: 'snow',\n\t\tdescription: 'heavy_shower_snow',\n\t},\n\t{\n\t\tid: 701,\n\t\tgroup: 'atmosphere',\n\t\tdescription: 'mist',\n\t},\n\t{\n\t\tid: 711,\n\t\tgroup: 'atmosphere',\n\t\tdescription: 'smoke',\n\t},\n\t{\n\t\tid: 721,\n\t\tgroup: 'atmosphere',\n\t\tdescription: 'haze',\n\t},\n\t{\n\t\tid: 731,\n\t\tgroup: 'atmosphere',\n\t\tdescription: 'sand_dust_whirls',\n\t},\n\t{\n\t\tid: 741,\n\t\tgroup: 'atmosphere',\n\t\tdescription: 'fog',\n\t},\n\t{\n\t\tid: 751,\n\t\tgroup: 'atmosphere',\n\t\tdescription: 'sand',\n\t},\n\t{\n\t\tid: 761,\n\t\tgroup: 'atmosphere',\n\t\tdescription: 'dust',\n\t},\n\t{\n\t\tid: 762,\n\t\tgroup: 'atmosphere',\n\t\tdescription: 'volcanic_ash',\n\t},\n\t{\n\t\tid: 771,\n\t\tgroup: 'atmosphere',\n\t\tdescription: 'squalls',\n\t},\n\t{\n\t\tid: 781,\n\t\tgroup: 'atmosphere',\n\t\tdescription: 'tornado',\n\t},\n\t{\n\t\tid: 800,\n\t\tgroup: 'clear',\n\t\tdescription: 'clear_sky',\n\t},\n\t{\n\t\tid: 801,\n\t\tgroup: 'clouds',\n\t\tdescription: 'few_clouds_11-25_percent',\n\t},\n\t{\n\t\tid: 802,\n\t\tgroup: 'clouds',\n\t\tdescription: 'scattered_clouds_25-50_percent',\n\t},\n\t{\n\t\tid: 803,\n\t\tgroup: 'clouds',\n\t\tdescription: 'broken_clouds_51-84_percent',\n\t},\n\t{\n\t\tid: 804,\n\t\tgroup: 'clouds',\n\t\tdescription: 'overcast_clouds_85-100_percent',\n\t},\n] as const;\n\nexport type WeatherID = (typeof weatherIdGroup)[number]['id'];\n\n/**\n * WeatherGroup: \"clouds\" | \"rain\" | \"snow\" | \"thunderstorm\" | \"drizzle\" | \"atmosphere\" | \"clear\"\n */\nexport type WeatherGroup = (typeof weatherIdGroup)[number]['group'];\n\n/**\n * List for weather description key types from OpenWeatherMap API based on weather id.\n *\n * This list of keys can be used to translate weather id to human readable description with different languages.\n * @example\n * const i18Weather: Record<WeatherDescription, string> = {\n * clear_sky: 'Clear sky',\n * ...\n * }\n */\nexport type WeatherDescription = (typeof weatherIdGroup)[number]['description'];\n\n/**\n * Weather id schema\n * @internal\n */\nexport const weatherIdSchema = z.custom<WeatherID>((val) => {\n\tif (typeof val !== 'number') {\n\t\treturn {message: 'Expected a number', success: false};\n\t}\n\tif (!weatherIdGroup.find((x) => x.id === val)) {\n\t\treturn {message: 'Expected a valid weather id', success: false};\n\t}\n\treturn val;\n});\n\n/**\n * get weather description key from weather id\n * @param id - weather id\n * @returns {Option<WeatherDescription>} option for weather description key\n * @example\n * const weatherComponent = ({data}) => {\n * const key = getWeatherV2Description(data.weather[0]?.id).unwrapOr('unknown');\n * return (\n * <div>\n * {t(`weather:${key}`}\n * </div>\n * );\n * }\n */\nexport function getWeatherV2Description(id: WeatherID | undefined): Option<WeatherDescription> {\n\treturn undefinedOptionWrap(weatherIdGroup.find((x) => x.id === id)?.description);\n}\n"]}
1
+ {"version":3,"file":"weatherIdGroup.js","sourceRoot":"./src/","sources":["types/v2/weatherIdGroup.ts"],"names":[],"mappings":";;;AAAA,8DAAuE;AACvE,6BAAsB;AAEtB;;GAEG;AACU,QAAA,cAAc,GAAG;IAC7B;QACC,EAAE,EAAE,GAAG;QACP,KAAK,EAAE,cAAc;QACrB,WAAW,EAAE,8BAA8B;KAC3C;IACD;QACC,EAAE,EAAE,GAAG;QACP,KAAK,EAAE,cAAc;QACrB,WAAW,EAAE,wBAAwB;KACrC;IACD;QACC,EAAE,EAAE,GAAG;QACP,KAAK,EAAE,cAAc;QACrB,WAAW,EAAE,8BAA8B;KAC3C;IACD;QACC,EAAE,EAAE,GAAG;QACP,KAAK,EAAE,cAAc;QACrB,WAAW,EAAE,oBAAoB;KACjC;IACD;QACC,EAAE,EAAE,GAAG;QACP,KAAK,EAAE,cAAc;QACrB,WAAW,EAAE,cAAc;KAC3B;IACD;QACC,EAAE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KAAK,EAAE,OAAO;QACd,WAAW,EAAE,WAAW;KACxB;IACD;QACC,EAAE,EAAE,GAAG;QACP,KAAK,EAAE,QAAQ;QACf,WAAW,EAAE,0BAA0B;KACvC;IACD;QACC,EAAE,EAAE,GAAG;QACP,KAAK,EAAE,QAAQ;QACf,WAAW,EAAE,gCAAgC;KAC7C;IACD;QACC,EAAE,EAAE,GAAG;QACP,KAAK,EAAE,QAAQ;QACf,WAAW,EAAE,6BAA6B;KAC1C;IACD;QACC,EAAE,EAAE,GAAG;QACP,KAAK,EAAE,QAAQ;QACf,WAAW,EAAE,gCAAgC;KAC7C;CACQ,CAAC;AAqBX;;;GAGG;AACU,QAAA,eAAe,GAAG,OAAC,CAAC,MAAM,CAAY,CAAC,GAAG,EAAE,EAAE;IAC1D,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;QAC5B,OAAO,EAAC,OAAO,EAAE,mBAAmB,EAAE,OAAO,EAAE,KAAK,EAAC,CAAC;KACtD;IACD,IAAI,CAAC,sBAAc,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,GAAG,CAAC,EAAE;QAC9C,OAAO,EAAC,OAAO,EAAE,6BAA6B,EAAE,OAAO,EAAE,KAAK,EAAC,CAAC;KAChE;IACD,OAAO,GAAG,CAAC;AACZ,CAAC,CAAC,CAAC;AAEH;;;;;;;;;;;;;GAaG;AACH,SAAgB,uBAAuB,CAAC,EAAyB;IAChE,OAAO,IAAA,mCAAmB,EAAC,sBAAc,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,WAAW,CAAC,CAAC;AAClF,CAAC;AAFD,0DAEC","sourcesContent":["import {Option, undefinedOptionWrap} from '@luolapeikko/result-option';\nimport {z} from 'zod';\n\n/**\n * This is a list of weather ids, groups and descriptions from OpenWeatherMap API\n */\nexport const weatherIdGroup = [\n\t{\n\t\tid: 200,\n\t\tgroup: 'thunderstorm',\n\t\tdescription: 'thunderstorm_with_light_rain',\n\t},\n\t{\n\t\tid: 201,\n\t\tgroup: 'thunderstorm',\n\t\tdescription: 'thunderstorm_with_rain',\n\t},\n\t{\n\t\tid: 202,\n\t\tgroup: 'thunderstorm',\n\t\tdescription: 'thunderstorm_with_heavy_rain',\n\t},\n\t{\n\t\tid: 210,\n\t\tgroup: 'thunderstorm',\n\t\tdescription: 'light_thunderstorm',\n\t},\n\t{\n\t\tid: 211,\n\t\tgroup: 'thunderstorm',\n\t\tdescription: 'thunderstorm',\n\t},\n\t{\n\t\tid: 212,\n\t\tgroup: 'thunderstorm',\n\t\tdescription: 'heavy_thunderstorm',\n\t},\n\t{\n\t\tid: 221,\n\t\tgroup: 'thunderstorm',\n\t\tdescription: 'ragged_thunderstorm',\n\t},\n\t{\n\t\tid: 230,\n\t\tgroup: 'thunderstorm',\n\t\tdescription: 'thunderstorm_with_light_drizzle',\n\t},\n\t{\n\t\tid: 231,\n\t\tgroup: 'thunderstorm',\n\t\tdescription: 'thunderstorm_with_drizzle',\n\t},\n\t{\n\t\tid: 232,\n\t\tgroup: 'thunderstorm',\n\t\tdescription: 'thunderstorm_with_heavy_drizzle',\n\t},\n\t{\n\t\tid: 300,\n\t\tgroup: 'drizzle',\n\t\tdescription: 'light_intensity_drizzle',\n\t},\n\t{\n\t\tid: 301,\n\t\tgroup: 'drizzle',\n\t\tdescription: 'drizzle',\n\t},\n\t{\n\t\tid: 302,\n\t\tgroup: 'drizzle',\n\t\tdescription: 'heavy_intensity_drizzle',\n\t},\n\t{\n\t\tid: 310,\n\t\tgroup: 'drizzle',\n\t\tdescription: 'light_intensity_drizzle_rain',\n\t},\n\t{\n\t\tid: 311,\n\t\tgroup: 'drizzle',\n\t\tdescription: 'drizzle_rain',\n\t},\n\t{\n\t\tid: 312,\n\t\tgroup: 'drizzle',\n\t\tdescription: 'heavy_intensity_drizzle_rain',\n\t},\n\t{\n\t\tid: 313,\n\t\tgroup: 'drizzle',\n\t\tdescription: 'shower_rain_and_drizzle',\n\t},\n\t{\n\t\tid: 314,\n\t\tgroup: 'drizzle',\n\t\tdescription: 'heavy_shower_rain_and_drizzle',\n\t},\n\t{\n\t\tid: 321,\n\t\tgroup: 'drizzle',\n\t\tdescription: 'shower_drizzle',\n\t},\n\t{\n\t\tid: 500,\n\t\tgroup: 'rain',\n\t\tdescription: 'light_rain',\n\t},\n\t{\n\t\tid: 501,\n\t\tgroup: 'rain',\n\t\tdescription: 'moderate_rain',\n\t},\n\t{\n\t\tid: 502,\n\t\tgroup: 'rain',\n\t\tdescription: 'heavy_intensity_rain',\n\t},\n\t{\n\t\tid: 503,\n\t\tgroup: 'rain',\n\t\tdescription: 'very_heavy_rain',\n\t},\n\t{\n\t\tid: 504,\n\t\tgroup: 'rain',\n\t\tdescription: 'extreme_rain',\n\t},\n\t{\n\t\tid: 511,\n\t\tgroup: 'rain',\n\t\tdescription: 'freezing_rain',\n\t},\n\t{\n\t\tid: 520,\n\t\tgroup: 'rain',\n\t\tdescription: 'light_intensity_shower_rain',\n\t},\n\t{\n\t\tid: 521,\n\t\tgroup: 'rain',\n\t\tdescription: 'shower_rain',\n\t},\n\t{\n\t\tid: 522,\n\t\tgroup: 'rain',\n\t\tdescription: 'heavy_intensity_shower_rain',\n\t},\n\t{\n\t\tid: 531,\n\t\tgroup: 'rain',\n\t\tdescription: 'ragged_shower_rain',\n\t},\n\t{\n\t\tid: 600,\n\t\tgroup: 'snow',\n\t\tdescription: 'light_snow',\n\t},\n\t{\n\t\tid: 601,\n\t\tgroup: 'snow',\n\t\tdescription: 'snow',\n\t},\n\t{\n\t\tid: 602,\n\t\tgroup: 'snow',\n\t\tdescription: 'heavy_snow',\n\t},\n\t{\n\t\tid: 611,\n\t\tgroup: 'snow',\n\t\tdescription: 'sleet',\n\t},\n\t{\n\t\tid: 612,\n\t\tgroup: 'snow',\n\t\tdescription: 'light_shower_sleet',\n\t},\n\t{\n\t\tid: 613,\n\t\tgroup: 'snow',\n\t\tdescription: 'shower_sleet',\n\t},\n\t{\n\t\tid: 615,\n\t\tgroup: 'snow',\n\t\tdescription: 'light_rain_and_snow',\n\t},\n\t{\n\t\tid: 616,\n\t\tgroup: 'snow',\n\t\tdescription: 'rain_and_snow',\n\t},\n\t{\n\t\tid: 620,\n\t\tgroup: 'snow',\n\t\tdescription: 'light_shower_snow',\n\t},\n\t{\n\t\tid: 621,\n\t\tgroup: 'snow',\n\t\tdescription: 'shower_snow',\n\t},\n\t{\n\t\tid: 622,\n\t\tgroup: 'snow',\n\t\tdescription: 'heavy_shower_snow',\n\t},\n\t{\n\t\tid: 701,\n\t\tgroup: 'atmosphere',\n\t\tdescription: 'mist',\n\t},\n\t{\n\t\tid: 711,\n\t\tgroup: 'atmosphere',\n\t\tdescription: 'smoke',\n\t},\n\t{\n\t\tid: 721,\n\t\tgroup: 'atmosphere',\n\t\tdescription: 'haze',\n\t},\n\t{\n\t\tid: 731,\n\t\tgroup: 'atmosphere',\n\t\tdescription: 'sand_dust_whirls',\n\t},\n\t{\n\t\tid: 741,\n\t\tgroup: 'atmosphere',\n\t\tdescription: 'fog',\n\t},\n\t{\n\t\tid: 751,\n\t\tgroup: 'atmosphere',\n\t\tdescription: 'sand',\n\t},\n\t{\n\t\tid: 761,\n\t\tgroup: 'atmosphere',\n\t\tdescription: 'dust',\n\t},\n\t{\n\t\tid: 762,\n\t\tgroup: 'atmosphere',\n\t\tdescription: 'volcanic_ash',\n\t},\n\t{\n\t\tid: 771,\n\t\tgroup: 'atmosphere',\n\t\tdescription: 'squalls',\n\t},\n\t{\n\t\tid: 781,\n\t\tgroup: 'atmosphere',\n\t\tdescription: 'tornado',\n\t},\n\t{\n\t\tid: 800,\n\t\tgroup: 'clear',\n\t\tdescription: 'clear_sky',\n\t},\n\t{\n\t\tid: 801,\n\t\tgroup: 'clouds',\n\t\tdescription: 'few_clouds_11-25_percent',\n\t},\n\t{\n\t\tid: 802,\n\t\tgroup: 'clouds',\n\t\tdescription: 'scattered_clouds_25-50_percent',\n\t},\n\t{\n\t\tid: 803,\n\t\tgroup: 'clouds',\n\t\tdescription: 'broken_clouds_51-84_percent',\n\t},\n\t{\n\t\tid: 804,\n\t\tgroup: 'clouds',\n\t\tdescription: 'overcast_clouds_85-100_percent',\n\t},\n] as const;\n\nexport type WeatherID = (typeof weatherIdGroup)[number]['id'];\n\n/**\n * WeatherGroup: \"clouds\" | \"rain\" | \"snow\" | \"thunderstorm\" | \"drizzle\" | \"atmosphere\" | \"clear\"\n */\nexport type WeatherGroup = (typeof weatherIdGroup)[number]['group'];\n\n/**\n * List for weather description key types from OpenWeatherMap API based on weather id.\n *\n * This list of keys can be used to translate weather id to human readable description with different languages.\n * @example\n * const i18Weather: Record<WeatherDescription, string> = {\n * clear_sky: 'Clear sky',\n * ...\n * }\n */\nexport type WeatherDescription = (typeof weatherIdGroup)[number]['description'];\n\n/**\n * Weather id schema\n * @internal\n */\nexport const weatherIdSchema = z.custom<WeatherID>((val) => {\n\tif (typeof val !== 'number') {\n\t\treturn {message: 'Expected a number', success: false};\n\t}\n\tif (!weatherIdGroup.find((x) => x.id === val)) {\n\t\treturn {message: 'Expected a valid weather id', success: false};\n\t}\n\treturn val;\n});\n\n/**\n * get weather description key from weather id\n * @param id - weather id\n * @returns {Option<WeatherDescription>} option for weather description key\n * @example\n * const weatherComponent = ({data}) => {\n * const key = getWeatherV2Description(data.weather[0]?.id).unwrapOr('unknown');\n * return (\n * <div>\n * {t(`weather:${key}`}\n * </div>\n * );\n * }\n */\nexport function getWeatherV2Description(id: WeatherID | undefined): Option<WeatherDescription> {\n\treturn undefinedOptionWrap(weatherIdGroup.find((x) => x.id === id)?.description);\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mharj/openweathermap",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "Open Weather API Client",
5
5
  "main": "./dist/index.js",
6
6
  "scripts": {
@@ -59,30 +59,30 @@
59
59
  },
60
60
  "homepage": "https://github.com/mharj/ts-openweather#readme",
61
61
  "dependencies": {
62
- "@avanio/expire-cache": "^0.3.2",
63
- "mharj-result": "^0.5.1",
64
- "tslib": "^2.6.1",
65
- "zod": "^3.21.4"
62
+ "@avanio/expire-cache": "^0.3.3",
63
+ "@luolapeikko/result-option": "^0.5.3",
64
+ "tslib": "^2.6.2",
65
+ "zod": "^3.23.0"
66
66
  },
67
67
  "devDependencies": {
68
- "@types/chai": "^4.3.5",
69
- "@types/mocha": "^10.0.1",
70
- "@types/node": "^18.17.2",
71
- "@typescript-eslint/eslint-plugin": "^6.2.1",
72
- "@typescript-eslint/parser": "^6.2.1",
73
- "chai": "^4.3.7",
74
- "eslint": "^8.46.0",
75
- "eslint-config-prettier": "^8.10.0",
68
+ "@types/chai": "^4.3.14",
69
+ "@types/mocha": "^10.0.6",
70
+ "@types/node": "^18.19.31",
71
+ "@typescript-eslint/eslint-plugin": "^7.7.0",
72
+ "@typescript-eslint/parser": "^7.7.0",
73
+ "chai": "^4.4.1",
74
+ "eslint": "^8.57.0",
75
+ "eslint-config-prettier": "^9.1.0",
76
76
  "eslint-config-standard": "^17.1.0",
77
- "eslint-plugin-deprecation": "^1.5.0",
78
- "eslint-plugin-prettier": "^5.0.0",
77
+ "eslint-plugin-deprecation": "^2.0.0",
78
+ "eslint-plugin-prettier": "^5.1.3",
79
79
  "eslint-plugin-sonarjs": "^0.19.0",
80
- "mocha": "^10.2.0",
80
+ "mocha": "^10.4.0",
81
81
  "nyc": "^15.1.0",
82
- "prettier": "^3.0.1",
82
+ "prettier": "^3.2.5",
83
83
  "source-map-support": "^0.5.21",
84
- "ts-node": "^10.9.1",
85
- "typedoc": "^0.24.8",
86
- "typedoc-plugin-zod": "^1.0.2"
84
+ "ts-node": "^10.9.2",
85
+ "typedoc": "^0.25.13",
86
+ "typedoc-plugin-zod": "^1.1.2"
87
87
  }
88
88
  }