@mharj/openweathermap 0.0.7 → 0.0.8
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.
- package/dist/index.d.mts +648 -0
- package/dist/index.d.ts +648 -4
- package/dist/index.js +937 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +899 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +35 -24
- package/dist/OpenWeatherV2.d.ts +0 -109
- package/dist/OpenWeatherV2.js +0 -219
- package/dist/OpenWeatherV2.js.map +0 -1
- package/dist/interfaces/IOpenWeatherV2.d.ts +0 -8
- package/dist/interfaces/IOpenWeatherV2.js +0 -3
- package/dist/interfaces/IOpenWeatherV2.js.map +0 -1
- package/dist/interfaces/index.d.ts +0 -1
- package/dist/interfaces/index.js +0 -5
- package/dist/interfaces/index.js.map +0 -1
- package/dist/lib/fetchUtils.d.ts +0 -5
- package/dist/lib/fetchUtils.js +0 -17
- package/dist/lib/fetchUtils.js.map +0 -1
- package/dist/lib/index.d.ts +0 -1
- package/dist/lib/index.js +0 -5
- package/dist/lib/index.js.map +0 -1
- package/dist/types/ISO3166-Countries.d.ts +0 -7
- package/dist/types/ISO3166-Countries.js +0 -260
- package/dist/types/ISO3166-Countries.js.map +0 -1
- package/dist/types/index.d.ts +0 -11
- package/dist/types/index.js +0 -11
- package/dist/types/index.js.map +0 -1
- package/dist/types/v2/Icon.d.ts +0 -17
- package/dist/types/v2/Icon.js +0 -19
- package/dist/types/v2/Icon.js.map +0 -1
- package/dist/types/v2/Language.d.ts +0 -4
- package/dist/types/v2/Language.js +0 -53
- package/dist/types/v2/Language.js.map +0 -1
- package/dist/types/v2/index.d.ts +0 -229
- package/dist/types/v2/index.js +0 -80
- package/dist/types/v2/index.js.map +0 -1
- package/dist/types/v2/weatherIdGroup.d.ts +0 -262
- package/dist/types/v2/weatherIdGroup.js +0 -317
- package/dist/types/v2/weatherIdGroup.js.map +0 -1
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,648 @@
|
|
|
1
|
+
import { IOption, IResult } from '@luolapeikko/result-option';
|
|
2
|
+
import { IAsyncCache } from '@luolapeikko/cache-types';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
declare const dayIconListSchema: z.ZodEnum<["01d", "02d", "03d", "04d", "09d", "10d", "11d", "13d", "50d"]>;
|
|
9
|
+
type DayIcon = z.infer<typeof dayIconListSchema>;
|
|
10
|
+
/**
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
declare const nightIconListSchema: z.ZodEnum<["01n", "02n", "03n", "04n", "09n", "10n", "11n", "13n", "50n"]>;
|
|
14
|
+
type NightIcon = z.infer<typeof nightIconListSchema>;
|
|
15
|
+
/**
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
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"]>]>;
|
|
19
|
+
type Icon = z.infer<typeof iconSchema>;
|
|
20
|
+
|
|
21
|
+
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"];
|
|
22
|
+
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"]>;
|
|
23
|
+
type LangCode = z.infer<typeof langCodeSchema>;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* This is a list of weather ids, groups and descriptions from OpenWeatherMap API
|
|
27
|
+
*/
|
|
28
|
+
declare const weatherIdGroup: readonly [{
|
|
29
|
+
readonly id: 200;
|
|
30
|
+
readonly group: "thunderstorm";
|
|
31
|
+
readonly description: "thunderstorm_with_light_rain";
|
|
32
|
+
}, {
|
|
33
|
+
readonly id: 201;
|
|
34
|
+
readonly group: "thunderstorm";
|
|
35
|
+
readonly description: "thunderstorm_with_rain";
|
|
36
|
+
}, {
|
|
37
|
+
readonly id: 202;
|
|
38
|
+
readonly group: "thunderstorm";
|
|
39
|
+
readonly description: "thunderstorm_with_heavy_rain";
|
|
40
|
+
}, {
|
|
41
|
+
readonly id: 210;
|
|
42
|
+
readonly group: "thunderstorm";
|
|
43
|
+
readonly description: "light_thunderstorm";
|
|
44
|
+
}, {
|
|
45
|
+
readonly id: 211;
|
|
46
|
+
readonly group: "thunderstorm";
|
|
47
|
+
readonly description: "thunderstorm";
|
|
48
|
+
}, {
|
|
49
|
+
readonly id: 212;
|
|
50
|
+
readonly group: "thunderstorm";
|
|
51
|
+
readonly description: "heavy_thunderstorm";
|
|
52
|
+
}, {
|
|
53
|
+
readonly id: 221;
|
|
54
|
+
readonly group: "thunderstorm";
|
|
55
|
+
readonly description: "ragged_thunderstorm";
|
|
56
|
+
}, {
|
|
57
|
+
readonly id: 230;
|
|
58
|
+
readonly group: "thunderstorm";
|
|
59
|
+
readonly description: "thunderstorm_with_light_drizzle";
|
|
60
|
+
}, {
|
|
61
|
+
readonly id: 231;
|
|
62
|
+
readonly group: "thunderstorm";
|
|
63
|
+
readonly description: "thunderstorm_with_drizzle";
|
|
64
|
+
}, {
|
|
65
|
+
readonly id: 232;
|
|
66
|
+
readonly group: "thunderstorm";
|
|
67
|
+
readonly description: "thunderstorm_with_heavy_drizzle";
|
|
68
|
+
}, {
|
|
69
|
+
readonly id: 300;
|
|
70
|
+
readonly group: "drizzle";
|
|
71
|
+
readonly description: "light_intensity_drizzle";
|
|
72
|
+
}, {
|
|
73
|
+
readonly id: 301;
|
|
74
|
+
readonly group: "drizzle";
|
|
75
|
+
readonly description: "drizzle";
|
|
76
|
+
}, {
|
|
77
|
+
readonly id: 302;
|
|
78
|
+
readonly group: "drizzle";
|
|
79
|
+
readonly description: "heavy_intensity_drizzle";
|
|
80
|
+
}, {
|
|
81
|
+
readonly id: 310;
|
|
82
|
+
readonly group: "drizzle";
|
|
83
|
+
readonly description: "light_intensity_drizzle_rain";
|
|
84
|
+
}, {
|
|
85
|
+
readonly id: 311;
|
|
86
|
+
readonly group: "drizzle";
|
|
87
|
+
readonly description: "drizzle_rain";
|
|
88
|
+
}, {
|
|
89
|
+
readonly id: 312;
|
|
90
|
+
readonly group: "drizzle";
|
|
91
|
+
readonly description: "heavy_intensity_drizzle_rain";
|
|
92
|
+
}, {
|
|
93
|
+
readonly id: 313;
|
|
94
|
+
readonly group: "drizzle";
|
|
95
|
+
readonly description: "shower_rain_and_drizzle";
|
|
96
|
+
}, {
|
|
97
|
+
readonly id: 314;
|
|
98
|
+
readonly group: "drizzle";
|
|
99
|
+
readonly description: "heavy_shower_rain_and_drizzle";
|
|
100
|
+
}, {
|
|
101
|
+
readonly id: 321;
|
|
102
|
+
readonly group: "drizzle";
|
|
103
|
+
readonly description: "shower_drizzle";
|
|
104
|
+
}, {
|
|
105
|
+
readonly id: 500;
|
|
106
|
+
readonly group: "rain";
|
|
107
|
+
readonly description: "light_rain";
|
|
108
|
+
}, {
|
|
109
|
+
readonly id: 501;
|
|
110
|
+
readonly group: "rain";
|
|
111
|
+
readonly description: "moderate_rain";
|
|
112
|
+
}, {
|
|
113
|
+
readonly id: 502;
|
|
114
|
+
readonly group: "rain";
|
|
115
|
+
readonly description: "heavy_intensity_rain";
|
|
116
|
+
}, {
|
|
117
|
+
readonly id: 503;
|
|
118
|
+
readonly group: "rain";
|
|
119
|
+
readonly description: "very_heavy_rain";
|
|
120
|
+
}, {
|
|
121
|
+
readonly id: 504;
|
|
122
|
+
readonly group: "rain";
|
|
123
|
+
readonly description: "extreme_rain";
|
|
124
|
+
}, {
|
|
125
|
+
readonly id: 511;
|
|
126
|
+
readonly group: "rain";
|
|
127
|
+
readonly description: "freezing_rain";
|
|
128
|
+
}, {
|
|
129
|
+
readonly id: 520;
|
|
130
|
+
readonly group: "rain";
|
|
131
|
+
readonly description: "light_intensity_shower_rain";
|
|
132
|
+
}, {
|
|
133
|
+
readonly id: 521;
|
|
134
|
+
readonly group: "rain";
|
|
135
|
+
readonly description: "shower_rain";
|
|
136
|
+
}, {
|
|
137
|
+
readonly id: 522;
|
|
138
|
+
readonly group: "rain";
|
|
139
|
+
readonly description: "heavy_intensity_shower_rain";
|
|
140
|
+
}, {
|
|
141
|
+
readonly id: 531;
|
|
142
|
+
readonly group: "rain";
|
|
143
|
+
readonly description: "ragged_shower_rain";
|
|
144
|
+
}, {
|
|
145
|
+
readonly id: 600;
|
|
146
|
+
readonly group: "snow";
|
|
147
|
+
readonly description: "light_snow";
|
|
148
|
+
}, {
|
|
149
|
+
readonly id: 601;
|
|
150
|
+
readonly group: "snow";
|
|
151
|
+
readonly description: "snow";
|
|
152
|
+
}, {
|
|
153
|
+
readonly id: 602;
|
|
154
|
+
readonly group: "snow";
|
|
155
|
+
readonly description: "heavy_snow";
|
|
156
|
+
}, {
|
|
157
|
+
readonly id: 611;
|
|
158
|
+
readonly group: "snow";
|
|
159
|
+
readonly description: "sleet";
|
|
160
|
+
}, {
|
|
161
|
+
readonly id: 612;
|
|
162
|
+
readonly group: "snow";
|
|
163
|
+
readonly description: "light_shower_sleet";
|
|
164
|
+
}, {
|
|
165
|
+
readonly id: 613;
|
|
166
|
+
readonly group: "snow";
|
|
167
|
+
readonly description: "shower_sleet";
|
|
168
|
+
}, {
|
|
169
|
+
readonly id: 615;
|
|
170
|
+
readonly group: "snow";
|
|
171
|
+
readonly description: "light_rain_and_snow";
|
|
172
|
+
}, {
|
|
173
|
+
readonly id: 616;
|
|
174
|
+
readonly group: "snow";
|
|
175
|
+
readonly description: "rain_and_snow";
|
|
176
|
+
}, {
|
|
177
|
+
readonly id: 620;
|
|
178
|
+
readonly group: "snow";
|
|
179
|
+
readonly description: "light_shower_snow";
|
|
180
|
+
}, {
|
|
181
|
+
readonly id: 621;
|
|
182
|
+
readonly group: "snow";
|
|
183
|
+
readonly description: "shower_snow";
|
|
184
|
+
}, {
|
|
185
|
+
readonly id: 622;
|
|
186
|
+
readonly group: "snow";
|
|
187
|
+
readonly description: "heavy_shower_snow";
|
|
188
|
+
}, {
|
|
189
|
+
readonly id: 701;
|
|
190
|
+
readonly group: "atmosphere";
|
|
191
|
+
readonly description: "mist";
|
|
192
|
+
}, {
|
|
193
|
+
readonly id: 711;
|
|
194
|
+
readonly group: "atmosphere";
|
|
195
|
+
readonly description: "smoke";
|
|
196
|
+
}, {
|
|
197
|
+
readonly id: 721;
|
|
198
|
+
readonly group: "atmosphere";
|
|
199
|
+
readonly description: "haze";
|
|
200
|
+
}, {
|
|
201
|
+
readonly id: 731;
|
|
202
|
+
readonly group: "atmosphere";
|
|
203
|
+
readonly description: "sand_dust_whirls";
|
|
204
|
+
}, {
|
|
205
|
+
readonly id: 741;
|
|
206
|
+
readonly group: "atmosphere";
|
|
207
|
+
readonly description: "fog";
|
|
208
|
+
}, {
|
|
209
|
+
readonly id: 751;
|
|
210
|
+
readonly group: "atmosphere";
|
|
211
|
+
readonly description: "sand";
|
|
212
|
+
}, {
|
|
213
|
+
readonly id: 761;
|
|
214
|
+
readonly group: "atmosphere";
|
|
215
|
+
readonly description: "dust";
|
|
216
|
+
}, {
|
|
217
|
+
readonly id: 762;
|
|
218
|
+
readonly group: "atmosphere";
|
|
219
|
+
readonly description: "volcanic_ash";
|
|
220
|
+
}, {
|
|
221
|
+
readonly id: 771;
|
|
222
|
+
readonly group: "atmosphere";
|
|
223
|
+
readonly description: "squalls";
|
|
224
|
+
}, {
|
|
225
|
+
readonly id: 781;
|
|
226
|
+
readonly group: "atmosphere";
|
|
227
|
+
readonly description: "tornado";
|
|
228
|
+
}, {
|
|
229
|
+
readonly id: 800;
|
|
230
|
+
readonly group: "clear";
|
|
231
|
+
readonly description: "clear_sky";
|
|
232
|
+
}, {
|
|
233
|
+
readonly id: 801;
|
|
234
|
+
readonly group: "clouds";
|
|
235
|
+
readonly description: "few_clouds_11-25_percent";
|
|
236
|
+
}, {
|
|
237
|
+
readonly id: 802;
|
|
238
|
+
readonly group: "clouds";
|
|
239
|
+
readonly description: "scattered_clouds_25-50_percent";
|
|
240
|
+
}, {
|
|
241
|
+
readonly id: 803;
|
|
242
|
+
readonly group: "clouds";
|
|
243
|
+
readonly description: "broken_clouds_51-84_percent";
|
|
244
|
+
}, {
|
|
245
|
+
readonly id: 804;
|
|
246
|
+
readonly group: "clouds";
|
|
247
|
+
readonly description: "overcast_clouds_85-100_percent";
|
|
248
|
+
}];
|
|
249
|
+
type WeatherID = (typeof weatherIdGroup)[number]['id'];
|
|
250
|
+
/**
|
|
251
|
+
* WeatherGroup: "clouds" | "rain" | "snow" | "thunderstorm" | "drizzle" | "atmosphere" | "clear"
|
|
252
|
+
*/
|
|
253
|
+
type WeatherGroup = (typeof weatherIdGroup)[number]['group'];
|
|
254
|
+
/**
|
|
255
|
+
* List for weather description key types from OpenWeatherMap API based on weather id.
|
|
256
|
+
*
|
|
257
|
+
* This list of keys can be used to translate weather id to human readable description with different languages.
|
|
258
|
+
* @example
|
|
259
|
+
* const i18Weather: Record<WeatherDescription, string> = {
|
|
260
|
+
* clear_sky: 'Clear sky',
|
|
261
|
+
* ...
|
|
262
|
+
* }
|
|
263
|
+
*/
|
|
264
|
+
type WeatherDescription = (typeof weatherIdGroup)[number]['description'];
|
|
265
|
+
/**
|
|
266
|
+
* Weather id schema
|
|
267
|
+
* @internal
|
|
268
|
+
*/
|
|
269
|
+
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>;
|
|
270
|
+
/**
|
|
271
|
+
* get weather description key from weather id
|
|
272
|
+
* @param id - weather id
|
|
273
|
+
* @returns {Option<WeatherDescription>} option for weather description key
|
|
274
|
+
* @example
|
|
275
|
+
* const weatherComponent = ({data}) => {
|
|
276
|
+
* const key = getWeatherV2Description(data.weather[0]?.id).unwrapOr('unknown');
|
|
277
|
+
* return (
|
|
278
|
+
* <div>
|
|
279
|
+
* {t(`weather:${key}`}
|
|
280
|
+
* </div>
|
|
281
|
+
* );
|
|
282
|
+
* }
|
|
283
|
+
*/
|
|
284
|
+
declare function getWeatherV2Description(id: WeatherID | undefined): IOption<WeatherDescription>;
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* @internal
|
|
288
|
+
*/
|
|
289
|
+
declare const weatherDataV2Schema: z.ZodObject<{
|
|
290
|
+
base: z.ZodString;
|
|
291
|
+
clouds: z.ZodObject<{
|
|
292
|
+
all: z.ZodNumber;
|
|
293
|
+
}, "strip", z.ZodTypeAny, {
|
|
294
|
+
all: number;
|
|
295
|
+
}, {
|
|
296
|
+
all: number;
|
|
297
|
+
}>;
|
|
298
|
+
cod: z.ZodNumber;
|
|
299
|
+
coord: z.ZodObject<{
|
|
300
|
+
lon: z.ZodNumber;
|
|
301
|
+
lat: z.ZodNumber;
|
|
302
|
+
}, "strip", z.ZodTypeAny, {
|
|
303
|
+
lon: number;
|
|
304
|
+
lat: number;
|
|
305
|
+
}, {
|
|
306
|
+
lon: number;
|
|
307
|
+
lat: number;
|
|
308
|
+
}>;
|
|
309
|
+
dt: z.ZodNumber;
|
|
310
|
+
id: z.ZodNumber;
|
|
311
|
+
main: z.ZodObject<{
|
|
312
|
+
grnd_level: z.ZodOptional<z.ZodNumber>;
|
|
313
|
+
humidity: z.ZodNumber;
|
|
314
|
+
pressure: z.ZodNumber;
|
|
315
|
+
sea_level: z.ZodOptional<z.ZodNumber>;
|
|
316
|
+
temp: z.ZodNumber;
|
|
317
|
+
temp_max: z.ZodNumber;
|
|
318
|
+
temp_min: z.ZodNumber;
|
|
319
|
+
}, "strip", z.ZodTypeAny, {
|
|
320
|
+
humidity: number;
|
|
321
|
+
pressure: number;
|
|
322
|
+
temp: number;
|
|
323
|
+
temp_max: number;
|
|
324
|
+
temp_min: number;
|
|
325
|
+
grnd_level?: number | undefined;
|
|
326
|
+
sea_level?: number | undefined;
|
|
327
|
+
}, {
|
|
328
|
+
humidity: number;
|
|
329
|
+
pressure: number;
|
|
330
|
+
temp: number;
|
|
331
|
+
temp_max: number;
|
|
332
|
+
temp_min: number;
|
|
333
|
+
grnd_level?: number | undefined;
|
|
334
|
+
sea_level?: number | undefined;
|
|
335
|
+
}>;
|
|
336
|
+
name: z.ZodString;
|
|
337
|
+
rain: z.ZodOptional<z.ZodObject<{
|
|
338
|
+
'1h': z.ZodOptional<z.ZodNumber>;
|
|
339
|
+
'3h': z.ZodOptional<z.ZodNumber>;
|
|
340
|
+
}, "strip", z.ZodTypeAny, {
|
|
341
|
+
'1h'?: number | undefined;
|
|
342
|
+
'3h'?: number | undefined;
|
|
343
|
+
}, {
|
|
344
|
+
'1h'?: number | undefined;
|
|
345
|
+
'3h'?: number | undefined;
|
|
346
|
+
}>>;
|
|
347
|
+
snow: z.ZodOptional<z.ZodObject<{
|
|
348
|
+
'1h': z.ZodOptional<z.ZodNumber>;
|
|
349
|
+
'3h': z.ZodOptional<z.ZodNumber>;
|
|
350
|
+
}, "strip", z.ZodTypeAny, {
|
|
351
|
+
'1h'?: number | undefined;
|
|
352
|
+
'3h'?: number | undefined;
|
|
353
|
+
}, {
|
|
354
|
+
'1h'?: number | undefined;
|
|
355
|
+
'3h'?: number | undefined;
|
|
356
|
+
}>>;
|
|
357
|
+
sys: z.ZodObject<{
|
|
358
|
+
country: z.ZodString;
|
|
359
|
+
id: z.ZodOptional<z.ZodNumber>;
|
|
360
|
+
message: z.ZodOptional<z.ZodNumber>;
|
|
361
|
+
sunrise: z.ZodNumber;
|
|
362
|
+
sunset: z.ZodNumber;
|
|
363
|
+
type: z.ZodOptional<z.ZodNumber>;
|
|
364
|
+
}, "strip", z.ZodTypeAny, {
|
|
365
|
+
country: string;
|
|
366
|
+
sunrise: number;
|
|
367
|
+
sunset: number;
|
|
368
|
+
message?: number | undefined;
|
|
369
|
+
type?: number | undefined;
|
|
370
|
+
id?: number | undefined;
|
|
371
|
+
}, {
|
|
372
|
+
country: string;
|
|
373
|
+
sunrise: number;
|
|
374
|
+
sunset: number;
|
|
375
|
+
message?: number | undefined;
|
|
376
|
+
type?: number | undefined;
|
|
377
|
+
id?: number | undefined;
|
|
378
|
+
}>;
|
|
379
|
+
timezone: z.ZodNumber;
|
|
380
|
+
visibility: z.ZodNumber;
|
|
381
|
+
weather: z.ZodArray<z.ZodObject<{
|
|
382
|
+
description: z.ZodString;
|
|
383
|
+
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"]>]>;
|
|
384
|
+
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>;
|
|
385
|
+
main: z.ZodString;
|
|
386
|
+
}, "strip", z.ZodTypeAny, {
|
|
387
|
+
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;
|
|
388
|
+
description: string;
|
|
389
|
+
icon: "01d" | "02d" | "03d" | "04d" | "09d" | "10d" | "11d" | "13d" | "50d" | "01n" | "02n" | "03n" | "04n" | "09n" | "10n" | "11n" | "13n" | "50n";
|
|
390
|
+
main: string;
|
|
391
|
+
}, {
|
|
392
|
+
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;
|
|
393
|
+
description: string;
|
|
394
|
+
icon: "01d" | "02d" | "03d" | "04d" | "09d" | "10d" | "11d" | "13d" | "50d" | "01n" | "02n" | "03n" | "04n" | "09n" | "10n" | "11n" | "13n" | "50n";
|
|
395
|
+
main: string;
|
|
396
|
+
}>, "many">;
|
|
397
|
+
wind: z.ZodObject<{
|
|
398
|
+
speed: z.ZodNumber;
|
|
399
|
+
deg: z.ZodNumber;
|
|
400
|
+
}, "strip", z.ZodTypeAny, {
|
|
401
|
+
speed: number;
|
|
402
|
+
deg: number;
|
|
403
|
+
}, {
|
|
404
|
+
speed: number;
|
|
405
|
+
deg: number;
|
|
406
|
+
}>;
|
|
407
|
+
}, "strip", z.ZodTypeAny, {
|
|
408
|
+
clouds: {
|
|
409
|
+
all: number;
|
|
410
|
+
};
|
|
411
|
+
id: number;
|
|
412
|
+
main: {
|
|
413
|
+
humidity: number;
|
|
414
|
+
pressure: number;
|
|
415
|
+
temp: number;
|
|
416
|
+
temp_max: number;
|
|
417
|
+
temp_min: number;
|
|
418
|
+
grnd_level?: number | undefined;
|
|
419
|
+
sea_level?: number | undefined;
|
|
420
|
+
};
|
|
421
|
+
base: string;
|
|
422
|
+
cod: number;
|
|
423
|
+
coord: {
|
|
424
|
+
lon: number;
|
|
425
|
+
lat: number;
|
|
426
|
+
};
|
|
427
|
+
dt: number;
|
|
428
|
+
name: string;
|
|
429
|
+
sys: {
|
|
430
|
+
country: string;
|
|
431
|
+
sunrise: number;
|
|
432
|
+
sunset: number;
|
|
433
|
+
message?: number | undefined;
|
|
434
|
+
type?: number | undefined;
|
|
435
|
+
id?: number | undefined;
|
|
436
|
+
};
|
|
437
|
+
timezone: number;
|
|
438
|
+
visibility: number;
|
|
439
|
+
weather: {
|
|
440
|
+
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;
|
|
441
|
+
description: string;
|
|
442
|
+
icon: "01d" | "02d" | "03d" | "04d" | "09d" | "10d" | "11d" | "13d" | "50d" | "01n" | "02n" | "03n" | "04n" | "09n" | "10n" | "11n" | "13n" | "50n";
|
|
443
|
+
main: string;
|
|
444
|
+
}[];
|
|
445
|
+
wind: {
|
|
446
|
+
speed: number;
|
|
447
|
+
deg: number;
|
|
448
|
+
};
|
|
449
|
+
rain?: {
|
|
450
|
+
'1h'?: number | undefined;
|
|
451
|
+
'3h'?: number | undefined;
|
|
452
|
+
} | undefined;
|
|
453
|
+
snow?: {
|
|
454
|
+
'1h'?: number | undefined;
|
|
455
|
+
'3h'?: number | undefined;
|
|
456
|
+
} | undefined;
|
|
457
|
+
}, {
|
|
458
|
+
clouds: {
|
|
459
|
+
all: number;
|
|
460
|
+
};
|
|
461
|
+
id: number;
|
|
462
|
+
main: {
|
|
463
|
+
humidity: number;
|
|
464
|
+
pressure: number;
|
|
465
|
+
temp: number;
|
|
466
|
+
temp_max: number;
|
|
467
|
+
temp_min: number;
|
|
468
|
+
grnd_level?: number | undefined;
|
|
469
|
+
sea_level?: number | undefined;
|
|
470
|
+
};
|
|
471
|
+
base: string;
|
|
472
|
+
cod: number;
|
|
473
|
+
coord: {
|
|
474
|
+
lon: number;
|
|
475
|
+
lat: number;
|
|
476
|
+
};
|
|
477
|
+
dt: number;
|
|
478
|
+
name: string;
|
|
479
|
+
sys: {
|
|
480
|
+
country: string;
|
|
481
|
+
sunrise: number;
|
|
482
|
+
sunset: number;
|
|
483
|
+
message?: number | undefined;
|
|
484
|
+
type?: number | undefined;
|
|
485
|
+
id?: number | undefined;
|
|
486
|
+
};
|
|
487
|
+
timezone: number;
|
|
488
|
+
visibility: number;
|
|
489
|
+
weather: {
|
|
490
|
+
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;
|
|
491
|
+
description: string;
|
|
492
|
+
icon: "01d" | "02d" | "03d" | "04d" | "09d" | "10d" | "11d" | "13d" | "50d" | "01n" | "02n" | "03n" | "04n" | "09n" | "10n" | "11n" | "13n" | "50n";
|
|
493
|
+
main: string;
|
|
494
|
+
}[];
|
|
495
|
+
wind: {
|
|
496
|
+
speed: number;
|
|
497
|
+
deg: number;
|
|
498
|
+
};
|
|
499
|
+
rain?: {
|
|
500
|
+
'1h'?: number | undefined;
|
|
501
|
+
'3h'?: number | undefined;
|
|
502
|
+
} | undefined;
|
|
503
|
+
snow?: {
|
|
504
|
+
'1h'?: number | undefined;
|
|
505
|
+
'3h'?: number | undefined;
|
|
506
|
+
} | undefined;
|
|
507
|
+
}>;
|
|
508
|
+
type WeatherDataV2 = z.infer<typeof weatherDataV2Schema>;
|
|
509
|
+
declare function isWeatherDataV2(data: unknown): data is WeatherDataV2;
|
|
510
|
+
declare function assertWeatherDataV2(data: unknown): asserts data is WeatherDataV2;
|
|
511
|
+
|
|
512
|
+
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"];
|
|
513
|
+
/**
|
|
514
|
+
* @internal
|
|
515
|
+
*/
|
|
516
|
+
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"]>;
|
|
517
|
+
type CountryCode = z.infer<typeof CountryCodeSchema>;
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* Generic argument which can be value, Promise of value, function which returns value or Promise of value.
|
|
521
|
+
* @example
|
|
522
|
+
* function solveLoadable(value: Loadable<string>): string | Promise<string> {
|
|
523
|
+
* return typeof value === 'function' ? value() : value;
|
|
524
|
+
* }
|
|
525
|
+
*/
|
|
526
|
+
type Loadable<T> = T | Promise<T> | (() => T) | (() => Promise<T>);
|
|
527
|
+
declare function solveLoadable(value: Loadable<string>): string | Promise<string>;
|
|
528
|
+
|
|
529
|
+
/**
|
|
530
|
+
* Interface for OpenWeatherMap API v2 implementation.
|
|
531
|
+
*/
|
|
532
|
+
interface IOpenWeatherV2 {
|
|
533
|
+
dataWeatherApi: (params: URLSearchParams) => Promise<IResult<WeatherDataV2, SyntaxError | TypeError>>;
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
/**
|
|
537
|
+
* Open Weather V2 API Common Options
|
|
538
|
+
* @default {lang: 'en', units: 'standard'} in API
|
|
539
|
+
* @example
|
|
540
|
+
* {lang: 'fi', units: 'metric'}
|
|
541
|
+
*/
|
|
542
|
+
type OpenWeatherV2CommonOptions = {
|
|
543
|
+
/**
|
|
544
|
+
* Language code
|
|
545
|
+
*/
|
|
546
|
+
lang?: LangCode;
|
|
547
|
+
/**
|
|
548
|
+
* Weather units
|
|
549
|
+
*/
|
|
550
|
+
units?: 'standard' | 'metric' | 'imperial';
|
|
551
|
+
};
|
|
552
|
+
/**
|
|
553
|
+
* Open Weather V2 API
|
|
554
|
+
* @example
|
|
555
|
+
* const weather = new OpenWeatherV2('your-api-key');
|
|
556
|
+
*
|
|
557
|
+
* const cache = new ExpireCache<WeatherDataV2>(undefined, undefined, 900000); // data 15 minutes in cache
|
|
558
|
+
* const weather = new OpenWeatherV2(() => Promise.resolve('your-api-key'), cache);
|
|
559
|
+
*
|
|
560
|
+
* const data: WeatherDataV2 = (await weather.getWeatherById(2643743)).unwrap(); // throws if error
|
|
561
|
+
* const data: WeatherDataV2 | undefined = (await weather.getWeatherByCity('Helsinki', 'fi')).ok();
|
|
562
|
+
*
|
|
563
|
+
* const result: Result<WeatherDataV2> = await weather.getWeatherByLatLon(60.1699, 24.9384);
|
|
564
|
+
* result.match({
|
|
565
|
+
* Ok: (data: WeatherDataV2) => console.log(data),
|
|
566
|
+
* Err: (err: DOMException | TypeError) => console.error(err),
|
|
567
|
+
* });
|
|
568
|
+
*
|
|
569
|
+
* if(result.isOk) {
|
|
570
|
+
* const data: WeatherDataV2 = data.ok();
|
|
571
|
+
* } else {
|
|
572
|
+
* const err: DOMException | TypeError = data.err();
|
|
573
|
+
* }
|
|
574
|
+
*/
|
|
575
|
+
declare class OpenWeatherV2 {
|
|
576
|
+
private cache;
|
|
577
|
+
private loadableApiKey;
|
|
578
|
+
private apiHandler;
|
|
579
|
+
private fetchPromiseMap;
|
|
580
|
+
/**
|
|
581
|
+
* OpenWeatherV2 constructor
|
|
582
|
+
* @param {Loadable<string>} loadableApiKey - Loadable API key
|
|
583
|
+
* @param {ICacheOrAsync<WeatherDataV2>=} cache - optional async cache implementation
|
|
584
|
+
* @param {IOpenWeatherV2=} apiHandler - optional API handler implementation for mocking
|
|
585
|
+
*/
|
|
586
|
+
constructor(loadableApiKey: Loadable<string>, cache?: IAsyncCache<WeatherDataV2>, apiHandler?: IOpenWeatherV2);
|
|
587
|
+
/**
|
|
588
|
+
* get weather by Id
|
|
589
|
+
* @param {number} id - Weather station ID
|
|
590
|
+
* @param {OpenWeatherV2CommonOptions=} opts - Common options, example ```{lang: 'fi', units: 'metric'}```, defaults ```{lang: 'en', units: 'standard'}```
|
|
591
|
+
* @return {Promise<Result<WeatherDataV2, DOMException | TypeError>>} Weather data Result Promise
|
|
592
|
+
* @example
|
|
593
|
+
* const result: Result<WeatherDataV2, DOMException | TypeError> = await weather.getWeatherResultById(id: 564, {lang: 'fi'});
|
|
594
|
+
* if (result.isOk) {
|
|
595
|
+
* const weatherData: WeatherDataV2 = result.ok();
|
|
596
|
+
* } else {
|
|
597
|
+
* const error: DOMException | TypeError = result.err();
|
|
598
|
+
* }
|
|
599
|
+
*/
|
|
600
|
+
getWeatherById(id: number, opts?: OpenWeatherV2CommonOptions): Promise<IResult<WeatherDataV2, DOMException | TypeError>>;
|
|
601
|
+
/**
|
|
602
|
+
* get weather with city name and optional country code
|
|
603
|
+
* @param {string} city - City name
|
|
604
|
+
* @param {countryCode=} countryCode - Optional Country code
|
|
605
|
+
* @param {OpenWeatherV2CommonOptions=} opts - Common options, example ```{lang: 'fi', units: 'metric'}```, defaults ```{lang: 'en', units: 'standard'}```
|
|
606
|
+
* @return {Promise<Result<WeatherDataV2, DOMException | TypeError>>} Weather data Result Promise
|
|
607
|
+
* @example
|
|
608
|
+
* const result: Result<WeatherDataV2, DOMException | TypeError> = await weather.getWeatherByCity('Helsinki', 'fi', {lang: 'fi'});
|
|
609
|
+
* if (result.isOk) {
|
|
610
|
+
* const weatherData: WeatherDataV2 = result.ok();
|
|
611
|
+
* } else {
|
|
612
|
+
* const error: DOMException | TypeError = result.err();
|
|
613
|
+
* }
|
|
614
|
+
*/
|
|
615
|
+
getWeatherByCity(city: string, countryCode?: CountryCode, opts?: OpenWeatherV2CommonOptions): Promise<IResult<WeatherDataV2, DOMException | TypeError>>;
|
|
616
|
+
/**
|
|
617
|
+
* get weather with latitude and longitude with Result
|
|
618
|
+
* @param {number} lat - Latitude
|
|
619
|
+
* @param {number} lon - Longitude
|
|
620
|
+
* @param {OpenWeatherV2CommonOptions=} opts - Common options, example ```{lang: 'fi', units: 'metric'}```, defaults ```{lang: 'en', units: 'standard'}```
|
|
621
|
+
* @return {Promise<Result<WeatherDataV2, DOMException | TypeError>>} Weather data Result Promise
|
|
622
|
+
* @example
|
|
623
|
+
* const result: Result<WeatherDataV2, DOMException | TypeError> = await weather.getWeatherByLatLon(60.1699, 24.9384, {lang: 'fi'});
|
|
624
|
+
* if (result.isOk) {
|
|
625
|
+
* const weatherData: WeatherDataV2 = result.ok();
|
|
626
|
+
* } else {
|
|
627
|
+
* const error: DOMException | TypeError = result.err();
|
|
628
|
+
* }
|
|
629
|
+
*/
|
|
630
|
+
getWeatherByLatLon(lat: number, lon: number, opts?: OpenWeatherV2CommonOptions): Promise<IResult<WeatherDataV2, DOMException | TypeError>>;
|
|
631
|
+
private buildBaseParams;
|
|
632
|
+
/**
|
|
633
|
+
* build base cache key
|
|
634
|
+
* @param main - main cache key prefix
|
|
635
|
+
* @param opts - OpenWeatherV2CommonOptions
|
|
636
|
+
* @returns {CacheKey}
|
|
637
|
+
*/
|
|
638
|
+
private buildBaseCacheKey;
|
|
639
|
+
private handleFetch;
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
/**
|
|
643
|
+
* Ensures that the error is a DOMException or TypeError.
|
|
644
|
+
* @internal
|
|
645
|
+
*/
|
|
646
|
+
declare function fetchErrorWrapper(err: unknown): DOMException | TypeError;
|
|
647
|
+
|
|
648
|
+
export { type CountryCode, CountryCodeList, CountryCodeSchema, type DayIcon, type IOpenWeatherV2, type Icon, type LangCode, type Loadable, type NightIcon, OpenWeatherV2, type OpenWeatherV2CommonOptions, type WeatherDataV2, type WeatherDescription, type WeatherGroup, type WeatherID, assertWeatherDataV2, fetchErrorWrapper, getWeatherV2Description, iconSchema, isWeatherDataV2, langCodeSchema, langCodes, solveLoadable, weatherDataV2Schema, weatherIdGroup, weatherIdSchema };
|