@mharj/openweathermap 0.0.7 → 0.1.0

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.
Files changed (40) hide show
  1. package/dist/index.d.mts +641 -0
  2. package/dist/index.d.ts +641 -4
  3. package/dist/index.js +940 -6
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +903 -0
  6. package/dist/index.mjs.map +1 -0
  7. package/package.json +45 -59
  8. package/dist/OpenWeatherV2.d.ts +0 -109
  9. package/dist/OpenWeatherV2.js +0 -219
  10. package/dist/OpenWeatherV2.js.map +0 -1
  11. package/dist/interfaces/IOpenWeatherV2.d.ts +0 -8
  12. package/dist/interfaces/IOpenWeatherV2.js +0 -3
  13. package/dist/interfaces/IOpenWeatherV2.js.map +0 -1
  14. package/dist/interfaces/index.d.ts +0 -1
  15. package/dist/interfaces/index.js +0 -5
  16. package/dist/interfaces/index.js.map +0 -1
  17. package/dist/lib/fetchUtils.d.ts +0 -5
  18. package/dist/lib/fetchUtils.js +0 -17
  19. package/dist/lib/fetchUtils.js.map +0 -1
  20. package/dist/lib/index.d.ts +0 -1
  21. package/dist/lib/index.js +0 -5
  22. package/dist/lib/index.js.map +0 -1
  23. package/dist/types/ISO3166-Countries.d.ts +0 -7
  24. package/dist/types/ISO3166-Countries.js +0 -260
  25. package/dist/types/ISO3166-Countries.js.map +0 -1
  26. package/dist/types/index.d.ts +0 -11
  27. package/dist/types/index.js +0 -11
  28. package/dist/types/index.js.map +0 -1
  29. package/dist/types/v2/Icon.d.ts +0 -17
  30. package/dist/types/v2/Icon.js +0 -19
  31. package/dist/types/v2/Icon.js.map +0 -1
  32. package/dist/types/v2/Language.d.ts +0 -4
  33. package/dist/types/v2/Language.js +0 -53
  34. package/dist/types/v2/Language.js.map +0 -1
  35. package/dist/types/v2/index.d.ts +0 -229
  36. package/dist/types/v2/index.js +0 -80
  37. package/dist/types/v2/index.js.map +0 -1
  38. package/dist/types/v2/weatherIdGroup.d.ts +0 -262
  39. package/dist/types/v2/weatherIdGroup.js +0 -317
  40. package/dist/types/v2/weatherIdGroup.js.map +0 -1
@@ -0,0 +1,641 @@
1
+ import { z } from 'zod';
2
+ import { IOption, IResult } from '@luolapeikko/result-option';
3
+ import { IAsyncCache } from '@luolapeikko/cache-types';
4
+ import { Loadable } from '@luolapeikko/ts-common';
5
+
6
+ /**
7
+ * @internal
8
+ */
9
+ declare const dayIconListSchema: z.ZodEnum<["01d", "02d", "03d", "04d", "09d", "10d", "11d", "13d", "50d"]>;
10
+ type DayIcon = z.infer<typeof dayIconListSchema>;
11
+ /**
12
+ * @internal
13
+ */
14
+ declare const nightIconListSchema: z.ZodEnum<["01n", "02n", "03n", "04n", "09n", "10n", "11n", "13n", "50n"]>;
15
+ type NightIcon = z.infer<typeof nightIconListSchema>;
16
+ /**
17
+ * @internal
18
+ */
19
+ declare const iconSchema: z.ZodUnion<[z.ZodEnum<["01d", "02d", "03d", "04d", "09d", "10d", "11d", "13d", "50d"]>, z.ZodEnum<["01n", "02n", "03n", "04n", "09n", "10n", "11n", "13n", "50n"]>]>;
20
+ type Icon = z.infer<typeof iconSchema>;
21
+
22
+ declare const langCodes: readonly ["af", "al", "ar", "az", "bg", "ca", "cz", "da", "de", "el", "en", "eu", "fa", "fi", "fr", "gl", "he", "hi", "hr", "hu", "id", "it", "ja", "kr", "la", "lt", "mk", "no", "nl", "pl", "pt", "pt", "ro", "ru", "sv", "sk", "sl", "sp", "sr", "th", "tr", "ua", "vi", "zh_cn", "zh_tw", "zu"];
23
+ declare const langCodeSchema: z.ZodEnum<["af", "al", "ar", "az", "bg", "ca", "cz", "da", "de", "el", "en", "eu", "fa", "fi", "fr", "gl", "he", "hi", "hr", "hu", "id", "it", "ja", "kr", "la", "lt", "mk", "no", "nl", "pl", "pt", "pt", "ro", "ru", "sv", "sk", "sl", "sp", "sr", "th", "tr", "ua", "vi", "zh_cn", "zh_tw", "zu"]>;
24
+ type LangCode = z.infer<typeof langCodeSchema>;
25
+
26
+ /**
27
+ * This is a list of weather ids, groups and descriptions from OpenWeatherMap API
28
+ */
29
+ declare const weatherIdGroup: readonly [{
30
+ readonly id: 200;
31
+ readonly group: "thunderstorm";
32
+ readonly description: "thunderstorm_with_light_rain";
33
+ }, {
34
+ readonly id: 201;
35
+ readonly group: "thunderstorm";
36
+ readonly description: "thunderstorm_with_rain";
37
+ }, {
38
+ readonly id: 202;
39
+ readonly group: "thunderstorm";
40
+ readonly description: "thunderstorm_with_heavy_rain";
41
+ }, {
42
+ readonly id: 210;
43
+ readonly group: "thunderstorm";
44
+ readonly description: "light_thunderstorm";
45
+ }, {
46
+ readonly id: 211;
47
+ readonly group: "thunderstorm";
48
+ readonly description: "thunderstorm";
49
+ }, {
50
+ readonly id: 212;
51
+ readonly group: "thunderstorm";
52
+ readonly description: "heavy_thunderstorm";
53
+ }, {
54
+ readonly id: 221;
55
+ readonly group: "thunderstorm";
56
+ readonly description: "ragged_thunderstorm";
57
+ }, {
58
+ readonly id: 230;
59
+ readonly group: "thunderstorm";
60
+ readonly description: "thunderstorm_with_light_drizzle";
61
+ }, {
62
+ readonly id: 231;
63
+ readonly group: "thunderstorm";
64
+ readonly description: "thunderstorm_with_drizzle";
65
+ }, {
66
+ readonly id: 232;
67
+ readonly group: "thunderstorm";
68
+ readonly description: "thunderstorm_with_heavy_drizzle";
69
+ }, {
70
+ readonly id: 300;
71
+ readonly group: "drizzle";
72
+ readonly description: "light_intensity_drizzle";
73
+ }, {
74
+ readonly id: 301;
75
+ readonly group: "drizzle";
76
+ readonly description: "drizzle";
77
+ }, {
78
+ readonly id: 302;
79
+ readonly group: "drizzle";
80
+ readonly description: "heavy_intensity_drizzle";
81
+ }, {
82
+ readonly id: 310;
83
+ readonly group: "drizzle";
84
+ readonly description: "light_intensity_drizzle_rain";
85
+ }, {
86
+ readonly id: 311;
87
+ readonly group: "drizzle";
88
+ readonly description: "drizzle_rain";
89
+ }, {
90
+ readonly id: 312;
91
+ readonly group: "drizzle";
92
+ readonly description: "heavy_intensity_drizzle_rain";
93
+ }, {
94
+ readonly id: 313;
95
+ readonly group: "drizzle";
96
+ readonly description: "shower_rain_and_drizzle";
97
+ }, {
98
+ readonly id: 314;
99
+ readonly group: "drizzle";
100
+ readonly description: "heavy_shower_rain_and_drizzle";
101
+ }, {
102
+ readonly id: 321;
103
+ readonly group: "drizzle";
104
+ readonly description: "shower_drizzle";
105
+ }, {
106
+ readonly id: 500;
107
+ readonly group: "rain";
108
+ readonly description: "light_rain";
109
+ }, {
110
+ readonly id: 501;
111
+ readonly group: "rain";
112
+ readonly description: "moderate_rain";
113
+ }, {
114
+ readonly id: 502;
115
+ readonly group: "rain";
116
+ readonly description: "heavy_intensity_rain";
117
+ }, {
118
+ readonly id: 503;
119
+ readonly group: "rain";
120
+ readonly description: "very_heavy_rain";
121
+ }, {
122
+ readonly id: 504;
123
+ readonly group: "rain";
124
+ readonly description: "extreme_rain";
125
+ }, {
126
+ readonly id: 511;
127
+ readonly group: "rain";
128
+ readonly description: "freezing_rain";
129
+ }, {
130
+ readonly id: 520;
131
+ readonly group: "rain";
132
+ readonly description: "light_intensity_shower_rain";
133
+ }, {
134
+ readonly id: 521;
135
+ readonly group: "rain";
136
+ readonly description: "shower_rain";
137
+ }, {
138
+ readonly id: 522;
139
+ readonly group: "rain";
140
+ readonly description: "heavy_intensity_shower_rain";
141
+ }, {
142
+ readonly id: 531;
143
+ readonly group: "rain";
144
+ readonly description: "ragged_shower_rain";
145
+ }, {
146
+ readonly id: 600;
147
+ readonly group: "snow";
148
+ readonly description: "light_snow";
149
+ }, {
150
+ readonly id: 601;
151
+ readonly group: "snow";
152
+ readonly description: "snow";
153
+ }, {
154
+ readonly id: 602;
155
+ readonly group: "snow";
156
+ readonly description: "heavy_snow";
157
+ }, {
158
+ readonly id: 611;
159
+ readonly group: "snow";
160
+ readonly description: "sleet";
161
+ }, {
162
+ readonly id: 612;
163
+ readonly group: "snow";
164
+ readonly description: "light_shower_sleet";
165
+ }, {
166
+ readonly id: 613;
167
+ readonly group: "snow";
168
+ readonly description: "shower_sleet";
169
+ }, {
170
+ readonly id: 615;
171
+ readonly group: "snow";
172
+ readonly description: "light_rain_and_snow";
173
+ }, {
174
+ readonly id: 616;
175
+ readonly group: "snow";
176
+ readonly description: "rain_and_snow";
177
+ }, {
178
+ readonly id: 620;
179
+ readonly group: "snow";
180
+ readonly description: "light_shower_snow";
181
+ }, {
182
+ readonly id: 621;
183
+ readonly group: "snow";
184
+ readonly description: "shower_snow";
185
+ }, {
186
+ readonly id: 622;
187
+ readonly group: "snow";
188
+ readonly description: "heavy_shower_snow";
189
+ }, {
190
+ readonly id: 701;
191
+ readonly group: "atmosphere";
192
+ readonly description: "mist";
193
+ }, {
194
+ readonly id: 711;
195
+ readonly group: "atmosphere";
196
+ readonly description: "smoke";
197
+ }, {
198
+ readonly id: 721;
199
+ readonly group: "atmosphere";
200
+ readonly description: "haze";
201
+ }, {
202
+ readonly id: 731;
203
+ readonly group: "atmosphere";
204
+ readonly description: "sand_dust_whirls";
205
+ }, {
206
+ readonly id: 741;
207
+ readonly group: "atmosphere";
208
+ readonly description: "fog";
209
+ }, {
210
+ readonly id: 751;
211
+ readonly group: "atmosphere";
212
+ readonly description: "sand";
213
+ }, {
214
+ readonly id: 761;
215
+ readonly group: "atmosphere";
216
+ readonly description: "dust";
217
+ }, {
218
+ readonly id: 762;
219
+ readonly group: "atmosphere";
220
+ readonly description: "volcanic_ash";
221
+ }, {
222
+ readonly id: 771;
223
+ readonly group: "atmosphere";
224
+ readonly description: "squalls";
225
+ }, {
226
+ readonly id: 781;
227
+ readonly group: "atmosphere";
228
+ readonly description: "tornado";
229
+ }, {
230
+ readonly id: 800;
231
+ readonly group: "clear";
232
+ readonly description: "clear_sky";
233
+ }, {
234
+ readonly id: 801;
235
+ readonly group: "clouds";
236
+ readonly description: "few_clouds_11-25_percent";
237
+ }, {
238
+ readonly id: 802;
239
+ readonly group: "clouds";
240
+ readonly description: "scattered_clouds_25-50_percent";
241
+ }, {
242
+ readonly id: 803;
243
+ readonly group: "clouds";
244
+ readonly description: "broken_clouds_51-84_percent";
245
+ }, {
246
+ readonly id: 804;
247
+ readonly group: "clouds";
248
+ readonly description: "overcast_clouds_85-100_percent";
249
+ }];
250
+ type WeatherID = (typeof weatherIdGroup)[number]['id'];
251
+ /**
252
+ * WeatherGroup: "clouds" | "rain" | "snow" | "thunderstorm" | "drizzle" | "atmosphere" | "clear"
253
+ */
254
+ type WeatherGroup = (typeof weatherIdGroup)[number]['group'];
255
+ /**
256
+ * List for weather description key types from OpenWeatherMap API based on weather id.
257
+ *
258
+ * This list of keys can be used to translate weather id to human readable description with different languages.
259
+ * @example
260
+ * const i18Weather: Record<WeatherDescription, string> = {
261
+ * clear_sky: 'Clear sky',
262
+ * ...
263
+ * }
264
+ */
265
+ type WeatherDescription = (typeof weatherIdGroup)[number]['description'];
266
+ /**
267
+ * Weather id schema
268
+ * @internal
269
+ */
270
+ declare const weatherIdSchema: z.ZodType<200 | 201 | 202 | 210 | 211 | 212 | 221 | 230 | 231 | 232 | 300 | 301 | 302 | 310 | 311 | 312 | 313 | 314 | 321 | 500 | 501 | 502 | 503 | 504 | 511 | 520 | 521 | 522 | 531 | 600 | 601 | 602 | 611 | 612 | 613 | 615 | 616 | 620 | 621 | 622 | 701 | 711 | 721 | 731 | 741 | 751 | 761 | 762 | 771 | 781 | 800 | 801 | 802 | 803 | 804, z.ZodTypeDef, 200 | 201 | 202 | 210 | 211 | 212 | 221 | 230 | 231 | 232 | 300 | 301 | 302 | 310 | 311 | 312 | 313 | 314 | 321 | 500 | 501 | 502 | 503 | 504 | 511 | 520 | 521 | 522 | 531 | 600 | 601 | 602 | 611 | 612 | 613 | 615 | 616 | 620 | 621 | 622 | 701 | 711 | 721 | 731 | 741 | 751 | 761 | 762 | 771 | 781 | 800 | 801 | 802 | 803 | 804>;
271
+ /**
272
+ * get weather description key from weather id
273
+ * @param id - weather id
274
+ * @returns {Option<WeatherDescription>} option for weather description key
275
+ * @example
276
+ * const weatherComponent = ({data}) => {
277
+ * const key = getWeatherV2Description(data.weather[0]?.id).unwrapOr('unknown');
278
+ * return (
279
+ * <div>
280
+ * {t(`weather:${key}`}
281
+ * </div>
282
+ * );
283
+ * }
284
+ */
285
+ declare function getWeatherV2Description(id: WeatherID | undefined): IOption<WeatherDescription>;
286
+
287
+ /**
288
+ * @internal
289
+ */
290
+ declare const weatherDataV2Schema: z.ZodObject<{
291
+ base: z.ZodString;
292
+ clouds: z.ZodObject<{
293
+ all: z.ZodNumber;
294
+ }, "strip", z.ZodTypeAny, {
295
+ all: number;
296
+ }, {
297
+ all: number;
298
+ }>;
299
+ cod: z.ZodNumber;
300
+ coord: z.ZodObject<{
301
+ lon: z.ZodNumber;
302
+ lat: z.ZodNumber;
303
+ }, "strip", z.ZodTypeAny, {
304
+ lon: number;
305
+ lat: number;
306
+ }, {
307
+ lon: number;
308
+ lat: number;
309
+ }>;
310
+ dt: z.ZodNumber;
311
+ id: z.ZodNumber;
312
+ main: z.ZodObject<{
313
+ grnd_level: z.ZodOptional<z.ZodNumber>;
314
+ humidity: z.ZodNumber;
315
+ pressure: z.ZodNumber;
316
+ sea_level: z.ZodOptional<z.ZodNumber>;
317
+ temp: z.ZodNumber;
318
+ temp_max: z.ZodNumber;
319
+ temp_min: z.ZodNumber;
320
+ }, "strip", z.ZodTypeAny, {
321
+ humidity: number;
322
+ pressure: number;
323
+ temp: number;
324
+ temp_max: number;
325
+ temp_min: number;
326
+ grnd_level?: number | undefined;
327
+ sea_level?: number | undefined;
328
+ }, {
329
+ humidity: number;
330
+ pressure: number;
331
+ temp: number;
332
+ temp_max: number;
333
+ temp_min: number;
334
+ grnd_level?: number | undefined;
335
+ sea_level?: number | undefined;
336
+ }>;
337
+ name: z.ZodString;
338
+ rain: z.ZodOptional<z.ZodObject<{
339
+ '1h': z.ZodOptional<z.ZodNumber>;
340
+ '3h': z.ZodOptional<z.ZodNumber>;
341
+ }, "strip", z.ZodTypeAny, {
342
+ '1h'?: number | undefined;
343
+ '3h'?: number | undefined;
344
+ }, {
345
+ '1h'?: number | undefined;
346
+ '3h'?: number | undefined;
347
+ }>>;
348
+ snow: z.ZodOptional<z.ZodObject<{
349
+ '1h': z.ZodOptional<z.ZodNumber>;
350
+ '3h': z.ZodOptional<z.ZodNumber>;
351
+ }, "strip", z.ZodTypeAny, {
352
+ '1h'?: number | undefined;
353
+ '3h'?: number | undefined;
354
+ }, {
355
+ '1h'?: number | undefined;
356
+ '3h'?: number | undefined;
357
+ }>>;
358
+ sys: z.ZodObject<{
359
+ country: z.ZodString;
360
+ id: z.ZodOptional<z.ZodNumber>;
361
+ message: z.ZodOptional<z.ZodNumber>;
362
+ sunrise: z.ZodNumber;
363
+ sunset: z.ZodNumber;
364
+ type: z.ZodOptional<z.ZodNumber>;
365
+ }, "strip", z.ZodTypeAny, {
366
+ country: string;
367
+ sunrise: number;
368
+ sunset: number;
369
+ message?: number | undefined;
370
+ type?: number | undefined;
371
+ id?: number | undefined;
372
+ }, {
373
+ country: string;
374
+ sunrise: number;
375
+ sunset: number;
376
+ message?: number | undefined;
377
+ type?: number | undefined;
378
+ id?: number | undefined;
379
+ }>;
380
+ timezone: z.ZodNumber;
381
+ visibility: z.ZodNumber;
382
+ weather: z.ZodArray<z.ZodObject<{
383
+ description: z.ZodString;
384
+ icon: z.ZodUnion<[z.ZodEnum<["01d", "02d", "03d", "04d", "09d", "10d", "11d", "13d", "50d"]>, z.ZodEnum<["01n", "02n", "03n", "04n", "09n", "10n", "11n", "13n", "50n"]>]>;
385
+ id: z.ZodType<200 | 201 | 202 | 210 | 211 | 212 | 221 | 230 | 231 | 232 | 300 | 301 | 302 | 310 | 311 | 312 | 313 | 314 | 321 | 500 | 501 | 502 | 503 | 504 | 511 | 520 | 521 | 522 | 531 | 600 | 601 | 602 | 611 | 612 | 613 | 615 | 616 | 620 | 621 | 622 | 701 | 711 | 721 | 731 | 741 | 751 | 761 | 762 | 771 | 781 | 800 | 801 | 802 | 803 | 804, z.ZodTypeDef, 200 | 201 | 202 | 210 | 211 | 212 | 221 | 230 | 231 | 232 | 300 | 301 | 302 | 310 | 311 | 312 | 313 | 314 | 321 | 500 | 501 | 502 | 503 | 504 | 511 | 520 | 521 | 522 | 531 | 600 | 601 | 602 | 611 | 612 | 613 | 615 | 616 | 620 | 621 | 622 | 701 | 711 | 721 | 731 | 741 | 751 | 761 | 762 | 771 | 781 | 800 | 801 | 802 | 803 | 804>;
386
+ main: z.ZodString;
387
+ }, "strip", z.ZodTypeAny, {
388
+ id: 200 | 201 | 202 | 210 | 211 | 212 | 221 | 230 | 231 | 232 | 300 | 301 | 302 | 310 | 311 | 312 | 313 | 314 | 321 | 500 | 501 | 502 | 503 | 504 | 511 | 520 | 521 | 522 | 531 | 600 | 601 | 602 | 611 | 612 | 613 | 615 | 616 | 620 | 621 | 622 | 701 | 711 | 721 | 731 | 741 | 751 | 761 | 762 | 771 | 781 | 800 | 801 | 802 | 803 | 804;
389
+ description: string;
390
+ icon: "01d" | "02d" | "03d" | "04d" | "09d" | "10d" | "11d" | "13d" | "50d" | "01n" | "02n" | "03n" | "04n" | "09n" | "10n" | "11n" | "13n" | "50n";
391
+ main: string;
392
+ }, {
393
+ id: 200 | 201 | 202 | 210 | 211 | 212 | 221 | 230 | 231 | 232 | 300 | 301 | 302 | 310 | 311 | 312 | 313 | 314 | 321 | 500 | 501 | 502 | 503 | 504 | 511 | 520 | 521 | 522 | 531 | 600 | 601 | 602 | 611 | 612 | 613 | 615 | 616 | 620 | 621 | 622 | 701 | 711 | 721 | 731 | 741 | 751 | 761 | 762 | 771 | 781 | 800 | 801 | 802 | 803 | 804;
394
+ description: string;
395
+ icon: "01d" | "02d" | "03d" | "04d" | "09d" | "10d" | "11d" | "13d" | "50d" | "01n" | "02n" | "03n" | "04n" | "09n" | "10n" | "11n" | "13n" | "50n";
396
+ main: string;
397
+ }>, "many">;
398
+ wind: z.ZodObject<{
399
+ speed: z.ZodNumber;
400
+ deg: z.ZodNumber;
401
+ }, "strip", z.ZodTypeAny, {
402
+ speed: number;
403
+ deg: number;
404
+ }, {
405
+ speed: number;
406
+ deg: number;
407
+ }>;
408
+ }, "strip", z.ZodTypeAny, {
409
+ clouds: {
410
+ all: number;
411
+ };
412
+ id: number;
413
+ main: {
414
+ humidity: number;
415
+ pressure: number;
416
+ temp: number;
417
+ temp_max: number;
418
+ temp_min: number;
419
+ grnd_level?: number | undefined;
420
+ sea_level?: number | undefined;
421
+ };
422
+ base: string;
423
+ cod: number;
424
+ coord: {
425
+ lon: number;
426
+ lat: number;
427
+ };
428
+ dt: number;
429
+ name: string;
430
+ sys: {
431
+ country: string;
432
+ sunrise: number;
433
+ sunset: number;
434
+ message?: number | undefined;
435
+ type?: number | undefined;
436
+ id?: number | undefined;
437
+ };
438
+ timezone: number;
439
+ visibility: number;
440
+ weather: {
441
+ id: 200 | 201 | 202 | 210 | 211 | 212 | 221 | 230 | 231 | 232 | 300 | 301 | 302 | 310 | 311 | 312 | 313 | 314 | 321 | 500 | 501 | 502 | 503 | 504 | 511 | 520 | 521 | 522 | 531 | 600 | 601 | 602 | 611 | 612 | 613 | 615 | 616 | 620 | 621 | 622 | 701 | 711 | 721 | 731 | 741 | 751 | 761 | 762 | 771 | 781 | 800 | 801 | 802 | 803 | 804;
442
+ description: string;
443
+ icon: "01d" | "02d" | "03d" | "04d" | "09d" | "10d" | "11d" | "13d" | "50d" | "01n" | "02n" | "03n" | "04n" | "09n" | "10n" | "11n" | "13n" | "50n";
444
+ main: string;
445
+ }[];
446
+ wind: {
447
+ speed: number;
448
+ deg: number;
449
+ };
450
+ rain?: {
451
+ '1h'?: number | undefined;
452
+ '3h'?: number | undefined;
453
+ } | undefined;
454
+ snow?: {
455
+ '1h'?: number | undefined;
456
+ '3h'?: number | undefined;
457
+ } | undefined;
458
+ }, {
459
+ clouds: {
460
+ all: number;
461
+ };
462
+ id: number;
463
+ main: {
464
+ humidity: number;
465
+ pressure: number;
466
+ temp: number;
467
+ temp_max: number;
468
+ temp_min: number;
469
+ grnd_level?: number | undefined;
470
+ sea_level?: number | undefined;
471
+ };
472
+ base: string;
473
+ cod: number;
474
+ coord: {
475
+ lon: number;
476
+ lat: number;
477
+ };
478
+ dt: number;
479
+ name: string;
480
+ sys: {
481
+ country: string;
482
+ sunrise: number;
483
+ sunset: number;
484
+ message?: number | undefined;
485
+ type?: number | undefined;
486
+ id?: number | undefined;
487
+ };
488
+ timezone: number;
489
+ visibility: number;
490
+ weather: {
491
+ id: 200 | 201 | 202 | 210 | 211 | 212 | 221 | 230 | 231 | 232 | 300 | 301 | 302 | 310 | 311 | 312 | 313 | 314 | 321 | 500 | 501 | 502 | 503 | 504 | 511 | 520 | 521 | 522 | 531 | 600 | 601 | 602 | 611 | 612 | 613 | 615 | 616 | 620 | 621 | 622 | 701 | 711 | 721 | 731 | 741 | 751 | 761 | 762 | 771 | 781 | 800 | 801 | 802 | 803 | 804;
492
+ description: string;
493
+ icon: "01d" | "02d" | "03d" | "04d" | "09d" | "10d" | "11d" | "13d" | "50d" | "01n" | "02n" | "03n" | "04n" | "09n" | "10n" | "11n" | "13n" | "50n";
494
+ main: string;
495
+ }[];
496
+ wind: {
497
+ speed: number;
498
+ deg: number;
499
+ };
500
+ rain?: {
501
+ '1h'?: number | undefined;
502
+ '3h'?: number | undefined;
503
+ } | undefined;
504
+ snow?: {
505
+ '1h'?: number | undefined;
506
+ '3h'?: number | undefined;
507
+ } | undefined;
508
+ }>;
509
+ type WeatherDataV2 = z.infer<typeof weatherDataV2Schema>;
510
+ declare function isWeatherDataV2(data: unknown): data is WeatherDataV2;
511
+ declare function assertWeatherDataV2(data: unknown): asserts data is WeatherDataV2;
512
+
513
+ declare const CountryCodeList: readonly ["af", "ax", "al", "dz", "as", "ad", "ao", "ai", "aq", "ag", "ar", "am", "aw", "au", "at", "az", "bs", "bh", "bd", "bb", "by", "be", "bz", "bj", "bm", "bt", "bo", "bq", "ba", "bw", "bv", "br", "io", "bn", "bg", "bf", "bi", "kh", "cm", "ca", "cv", "ky", "cf", "td", "cl", "cn", "cx", "cc", "co", "km", "cg", "cd", "ck", "cr", "ci", "hr", "cu", "cw", "cy", "cz", "dk", "dj", "dm", "do", "ec", "eg", "sv", "gq", "er", "ee", "et", "fk", "fo", "fj", "fi", "fr", "gf", "pf", "tf", "ga", "gm", "ge", "de", "gh", "gi", "gr", "gl", "gd", "gp", "gu", "gt", "gg", "gn", "gw", "gy", "ht", "hm", "va", "hn", "hk", "hu", "is", "in", "id", "ir", "iq", "ie", "im", "il", "it", "jm", "jp", "je", "jo", "kz", "ke", "ki", "kp", "kr", "kw", "kg", "la", "lv", "lb", "ls", "lr", "ly", "li", "lt", "lu", "mo", "mk", "mg", "mw", "my", "mv", "ml", "mt", "mh", "mq", "mr", "mu", "yt", "mx", "fm", "md", "mc", "mn", "me", "ms", "ma", "mz", "mm", "na", "nr", "np", "nl", "nc", "nz", "ni", "ne", "ng", "nu", "nf", "mp", "no", "om", "pk", "pw", "ps", "pa", "pg", "py", "pe", "ph", "pn", "pl", "pt", "pr", "qa", "re", "ro", "ru", "rw", "bl", "sh", "kn", "lc", "mf", "pm", "vc", "ws", "sm", "st", "sa", "sn", "rs", "sc", "sl", "sg", "sx", "sk", "si", "sb", "so", "za", "gs", "ss", "es", "lk", "sd", "sr", "sj", "sz", "se", "ch", "sy", "tw", "tj", "tz", "th", "tl", "tg", "tk", "to", "tt", "tn", "tr", "tm", "tc", "tv", "ug", "ua", "ae", "gb", "us", "um", "uy", "uz", "vu", "ve", "vn", "vg", "vi", "wf", "eh", "ye", "zm", "zw"];
514
+ /**
515
+ * @internal
516
+ */
517
+ declare const CountryCodeSchema: z.ZodEnum<["af", "ax", "al", "dz", "as", "ad", "ao", "ai", "aq", "ag", "ar", "am", "aw", "au", "at", "az", "bs", "bh", "bd", "bb", "by", "be", "bz", "bj", "bm", "bt", "bo", "bq", "ba", "bw", "bv", "br", "io", "bn", "bg", "bf", "bi", "kh", "cm", "ca", "cv", "ky", "cf", "td", "cl", "cn", "cx", "cc", "co", "km", "cg", "cd", "ck", "cr", "ci", "hr", "cu", "cw", "cy", "cz", "dk", "dj", "dm", "do", "ec", "eg", "sv", "gq", "er", "ee", "et", "fk", "fo", "fj", "fi", "fr", "gf", "pf", "tf", "ga", "gm", "ge", "de", "gh", "gi", "gr", "gl", "gd", "gp", "gu", "gt", "gg", "gn", "gw", "gy", "ht", "hm", "va", "hn", "hk", "hu", "is", "in", "id", "ir", "iq", "ie", "im", "il", "it", "jm", "jp", "je", "jo", "kz", "ke", "ki", "kp", "kr", "kw", "kg", "la", "lv", "lb", "ls", "lr", "ly", "li", "lt", "lu", "mo", "mk", "mg", "mw", "my", "mv", "ml", "mt", "mh", "mq", "mr", "mu", "yt", "mx", "fm", "md", "mc", "mn", "me", "ms", "ma", "mz", "mm", "na", "nr", "np", "nl", "nc", "nz", "ni", "ne", "ng", "nu", "nf", "mp", "no", "om", "pk", "pw", "ps", "pa", "pg", "py", "pe", "ph", "pn", "pl", "pt", "pr", "qa", "re", "ro", "ru", "rw", "bl", "sh", "kn", "lc", "mf", "pm", "vc", "ws", "sm", "st", "sa", "sn", "rs", "sc", "sl", "sg", "sx", "sk", "si", "sb", "so", "za", "gs", "ss", "es", "lk", "sd", "sr", "sj", "sz", "se", "ch", "sy", "tw", "tj", "tz", "th", "tl", "tg", "tk", "to", "tt", "tn", "tr", "tm", "tc", "tv", "ug", "ua", "ae", "gb", "us", "um", "uy", "uz", "vu", "ve", "vn", "vg", "vi", "wf", "eh", "ye", "zm", "zw"]>;
518
+ type CountryCode = z.infer<typeof CountryCodeSchema>;
519
+
520
+ /**
521
+ * Interface for OpenWeatherMap API v2 implementation.
522
+ */
523
+ interface IOpenWeatherV2 {
524
+ dataWeatherApi: (params: URLSearchParams) => Promise<IResult<WeatherDataV2, SyntaxError | TypeError>>;
525
+ }
526
+
527
+ /**
528
+ * Open Weather V2 API Common Options
529
+ * @default {lang: 'en', units: 'standard'} in API
530
+ * @example
531
+ * {lang: 'fi', units: 'metric'}
532
+ * @since v0.0.1
533
+ */
534
+ type OpenWeatherV2CommonOptions = {
535
+ /**
536
+ * Language code
537
+ */
538
+ lang: LangCode;
539
+ /**
540
+ * Weather units
541
+ */
542
+ units: 'standard' | 'metric' | 'imperial';
543
+ };
544
+ /**
545
+ * Open Weather V2 API
546
+ * @example
547
+ * const weather = new OpenWeatherV2('your-api-key');
548
+ *
549
+ * const cache = new ExpireCache<WeatherDataV2>(undefined, undefined, 900000); // data 15 minutes in cache
550
+ * const weather = new OpenWeatherV2(() => Promise.resolve('your-api-key'), cache);
551
+ *
552
+ * const data: WeatherDataV2 = (await weather.getWeatherById(2643743)).unwrap(); // throws if error
553
+ * const data: WeatherDataV2 | undefined = (await weather.getWeatherByCity('Helsinki', 'fi')).ok();
554
+ *
555
+ * const result: Result<WeatherDataV2> = await weather.getWeatherByLatLon(60.1699, 24.9384);
556
+ * result.match({
557
+ * Ok: (data: WeatherDataV2) => console.log(data),
558
+ * Err: (err: DOMException | TypeError) => console.error(err),
559
+ * });
560
+ *
561
+ * if(result.isOk) {
562
+ * const data: WeatherDataV2 = data.ok();
563
+ * } else {
564
+ * const err: DOMException | TypeError = data.err();
565
+ * }
566
+ * @since v0.0.1
567
+ */
568
+ declare class OpenWeatherV2 {
569
+ private cache;
570
+ private loadableApiKey;
571
+ private apiHandler;
572
+ private fetchPromiseMap;
573
+ /**
574
+ * OpenWeatherV2 constructor
575
+ * @param {Loadable<string>} loadableApiKey - Loadable API key
576
+ * @param {ICacheOrAsync<WeatherDataV2>=} cache - optional async cache implementation
577
+ * @param {IOpenWeatherV2=} apiHandler - optional API handler implementation for mocking
578
+ */
579
+ constructor(loadableApiKey: Loadable<string>, cache?: IAsyncCache<WeatherDataV2>, apiHandler?: IOpenWeatherV2);
580
+ /**
581
+ * get weather by Id
582
+ * @param {number} id - Weather station ID
583
+ * @param {OpenWeatherV2CommonOptions=} currentOpts - Common options, example ```{lang: 'fi', units: 'metric'}```, defaults ```{lang: 'en', units: 'standard'}```
584
+ * @return {Promise<Result<WeatherDataV2, DOMException | TypeError>>} Weather data Result Promise
585
+ * @example
586
+ * const result: Result<WeatherDataV2, DOMException | TypeError> = await weather.getWeatherResultById(id: 564, {lang: 'fi'});
587
+ * if (result.isOk) {
588
+ * const weatherData: WeatherDataV2 = result.ok();
589
+ * } else {
590
+ * const error: DOMException | TypeError = result.err();
591
+ * }
592
+ */
593
+ getWeatherById(id: number, currentOpts?: Partial<OpenWeatherV2CommonOptions>): Promise<IResult<WeatherDataV2, DOMException | TypeError>>;
594
+ /**
595
+ * get weather with city name and optional country code
596
+ * @param {string} city - City name
597
+ * @param {countryCode=} countryCode - Optional Country code
598
+ * @param {OpenWeatherV2CommonOptions=} currentOpts - Common options, example ```{lang: 'fi', units: 'metric'}```, defaults ```{lang: 'en', units: 'standard'}```
599
+ * @return {Promise<Result<WeatherDataV2, DOMException | TypeError>>} Weather data Result Promise
600
+ * @example
601
+ * const result: Result<WeatherDataV2, DOMException | TypeError> = await weather.getWeatherByCity('Helsinki', 'fi', {lang: 'fi'});
602
+ * if (result.isOk) {
603
+ * const weatherData: WeatherDataV2 = result.ok();
604
+ * } else {
605
+ * const error: DOMException | TypeError = result.err();
606
+ * }
607
+ */
608
+ getWeatherByCity(city: string, countryCode?: CountryCode, currentOpts?: Partial<OpenWeatherV2CommonOptions>): Promise<IResult<WeatherDataV2, DOMException | TypeError>>;
609
+ /**
610
+ * get weather with latitude and longitude with Result
611
+ * @param {number} lat - Latitude
612
+ * @param {number} lon - Longitude
613
+ * @param {OpenWeatherV2CommonOptions=} currentOpts - Common options, example ```{lang: 'fi', units: 'metric'}```, defaults ```{lang: 'en', units: 'standard'}```
614
+ * @return {Promise<Result<WeatherDataV2, DOMException | TypeError>>} Weather data Result Promise
615
+ * @example
616
+ * const result: Result<WeatherDataV2, DOMException | TypeError> = await weather.getWeatherByLatLon(60.1699, 24.9384, {lang: 'fi'});
617
+ * if (result.isOk) {
618
+ * const weatherData: WeatherDataV2 = result.ok();
619
+ * } else {
620
+ * const error: DOMException | TypeError = result.err();
621
+ * }
622
+ */
623
+ getWeatherByLatLon(lat: number, lon: number, currentOpts?: Partial<OpenWeatherV2CommonOptions>): Promise<IResult<WeatherDataV2, DOMException | TypeError>>;
624
+ private buildBaseParams;
625
+ /**
626
+ * build base cache key
627
+ * @param main - main cache key prefix
628
+ * @param opts - OpenWeatherV2CommonOptions
629
+ * @returns {string} cache key
630
+ */
631
+ private buildBaseCacheKey;
632
+ private handleFetch;
633
+ }
634
+
635
+ /**
636
+ * Ensures that the error is a DOMException or TypeError.
637
+ * @internal
638
+ */
639
+ declare function fetchErrorWrapper(err: unknown): DOMException | TypeError;
640
+
641
+ export { type CountryCode, CountryCodeList, CountryCodeSchema, type DayIcon, type IOpenWeatherV2, type Icon, type LangCode, type NightIcon, OpenWeatherV2, type OpenWeatherV2CommonOptions, type WeatherDataV2, type WeatherDescription, type WeatherGroup, type WeatherID, assertWeatherDataV2, fetchErrorWrapper, getWeatherV2Description, iconSchema, isWeatherDataV2, langCodeSchema, langCodes, weatherDataV2Schema, weatherIdGroup, weatherIdSchema };