@alwatr/fetch 0.18.0 → 0.20.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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,25 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [0.20.0](https://github.com/AliMD/alwatr/compare/v0.19.0...v0.20.0) (2022-11-05)
7
+
8
+ ### Bug Fixes
9
+
10
+ - **fetch:** \_handleRemoveDuplicate ([6207b48](https://github.com/AliMD/alwatr/commit/6207b4867935d05a0e5a1c795de9efab4ff77c68))
11
+ - **fetch:** cacheStorageName issue ([e641ff7](https://github.com/AliMD/alwatr/commit/e641ff740055a68b6397f00bf46f1d05943c348a))
12
+ - **fetch:** method type and case ([8d4ba77](https://github.com/AliMD/alwatr/commit/8d4ba77e56ecfe2aeaa459dcd26039c38c4b2199))
13
+ - **fetch:** prevent duplicate revalidateCallback on first time ([2da7dc5](https://github.com/AliMD/alwatr/commit/2da7dc579e4850af06914590a231548cd469cd75))
14
+
15
+ ### Features
16
+
17
+ - **fetch:** add retryDelay ([28e3244](https://github.com/AliMD/alwatr/commit/28e3244a2d35e7a1a91f9a5a4942f1bb4a56d981))
18
+ - **fetch:** revalidate callback for `stale_while_revalidate` cache strategy. ([8976cc4](https://github.com/AliMD/alwatr/commit/8976cc424b2a9e96e4cfa69941d5378a6640af6f))
19
+ - **fetch:** simple memory caching for remove duplicate/parallel requests ([74cd7f1](https://github.com/AliMD/alwatr/commit/74cd7f1500d730021a0f577c0ecfd7a2460fdb15))
20
+
21
+ # [0.19.0](https://github.com/AliMD/alwatr/compare/v0.18.0...v0.19.0) (2022-11-01)
22
+
23
+ **Note:** Version bump only for package @alwatr/fetch
24
+
6
25
  # [0.18.0](https://github.com/AliMD/alwatr/compare/v0.17.0...v0.18.0) (2022-10-22)
7
26
 
8
27
  ### Bug Fixes
package/README.md CHANGED
@@ -30,15 +30,22 @@ const productList = await getJson<Record<string, ProductInterface>>({
30
30
  - `url`: Request URL.
31
31
  - `bodyJson`: Body as JS Object.
32
32
  - `queryParameters`: URL Query Parameters as JS Object.
33
- - `timeout`: A timeout in ms for the fetch request (default `5000`ms).
33
+ - `timeout`: A timeout in ms for the fetch request (default `10_000`ms).
34
34
  - `retry`: If fetch response not acceptable or timed out, it will retry the request (default `3`).
35
- - `cacheStorageName`: Cache storage name (default `alwatr_fetch_cache`).
36
- - `cacheStrategy`: Strategies for caching, (default `network_only`).
35
+ - `retryDelay`: Delay before each retries (default `1_000`).
36
+ - `removeDuplicate`: Simple memory caching for remove duplicate/parallel requests (default `never`).
37
+ - `never`: Never use memory caching.
38
+ - `always`: Always use memory caching and remove all duplicate requests (just by method+url).
39
+ - `until_load`: Cache parallel requests until request completed (it will be removed after the promise resolved).
40
+ - `auto`: If CacheStorage was supported use `until_load` strategy else use `always`.
41
+ - `cacheStrategy`: Strategies for caching (default `network_only`).
37
42
  - `network_only`: Only network request without any cache.
38
43
  - `network_first`: Network first, falling back to cache.
39
44
  - `cache_only`: Cache only without any network request.
40
45
  - `cache_first`: Cache first, falling back to network.
41
46
  - `stale_while_revalidate`: Fastest strategy, Use cached first but always request network to update the cache.
47
+ - `revalidateCallback`: Revalidate callback for `stale_while_revalidate` cache strategy.
48
+ - `cacheStorageName`: Cache storage custom name (default `alwatr_fetch_cache`).
42
49
 
43
50
  [Read more about standard cache strategies](https://developer.chrome.com/docs/workbox/caching-strategies-overview/#caching-strategies)
44
51
 
package/fetch.d.ts CHANGED
@@ -1,18 +1,18 @@
1
- declare global {
2
- interface AbortController {
3
- abort(reason?: string): void;
4
- }
5
- }
6
1
  export declare type CacheStrategy = 'network_only' | 'network_first' | 'cache_only' | 'cache_first' | 'stale_while_revalidate';
2
+ export declare type CacheDuplicate = 'never' | 'always' | 'until_load' | 'auto';
7
3
  export interface FetchOptions extends RequestInit {
8
4
  /**
9
5
  * Request URL.
10
6
  */
11
7
  url: string;
8
+ /**
9
+ * A string to set request's method.
10
+ */
11
+ method: string;
12
12
  /**
13
13
  * A timeout for the fetch request.
14
14
  *
15
- * @default 5000 ms
15
+ * @default 10_000 ms
16
16
  */
17
17
  timeout: number;
18
18
  /**
@@ -21,18 +21,43 @@ export interface FetchOptions extends RequestInit {
21
21
  * @default 3
22
22
  */
23
23
  retry: number;
24
+ /**
25
+ * Delay before each retries.
26
+ *
27
+ * @default 1_000 ms
28
+ */
29
+ retryDelay: number;
30
+ /**
31
+ * Simple memory caching for remove duplicate/parallel requests.
32
+ *
33
+ * - `never`: Never use memory caching.
34
+ * - `always`: Always use memory caching and remove all duplicate requests.
35
+ * - `until_load`: Cache parallel requests until request completed (it will be removed after the promise resolved).
36
+ * - `auto`: If CacheStorage was supported use `until_load` strategy else use `always`.
37
+ *
38
+ * @default 'never'
39
+ */
40
+ removeDuplicate: CacheDuplicate;
24
41
  /**
25
42
  * Strategies for caching.
26
43
  *
44
+ * - `network_only`: Only network request without any cache.
45
+ * - `network_first`: Network first, falling back to cache.
46
+ * - `cache_only`: Cache only without any network request.
47
+ * - `cache_first`: Cache first, falling back to network.
48
+ * - `stale_while_revalidate`: Fastest strategy, Use cached first but always request network to update the cache.
49
+ *
27
50
  * @default 'network_only'
28
51
  */
29
52
  cacheStrategy: CacheStrategy;
30
53
  /**
31
- * Cache storage name.
32
- *
33
- * @default 'alwatr_fetch_cache'
54
+ * Revalidate callback for `stale_while_revalidate` cache strategy.
55
+ */
56
+ revalidateCallback?: (response: Response) => void;
57
+ /**
58
+ * Cache storage custom name.
34
59
  */
35
- cacheStorageName: string;
60
+ cacheStorageName?: string;
36
61
  /**
37
62
  * Body as JS Object.
38
63
  */
@@ -43,39 +68,42 @@ export interface FetchOptions extends RequestInit {
43
68
  queryParameters?: Record<string, string | number | boolean>;
44
69
  }
45
70
  /**
46
- * It's a wrapper around the browser's `fetch` function that adds retry pattern with timeout and cacheStrategy.
71
+ * It fetches a JSON file from a URL, and returns the parsed data.
47
72
  *
48
73
  * Example:
49
74
  *
50
75
  * ```ts
51
- * const response = await fetch({
76
+ * const productList = await getJson<ProductResponse>({
52
77
  * url: '/api/products',
53
78
  * queryParameters: {limit: 10},
54
- * timeout: 5_000,
79
+ * timeout: 10_000,
55
80
  * retry: 3,
56
81
  * cacheStrategy: 'stale_while_revalidate',
82
+ * cacheDuplicate: 'auto',
57
83
  * });
58
84
  * ```
59
85
  */
60
- export declare function fetch(_options: Partial<FetchOptions> & {
86
+ export declare function getJson<ResponseType extends Record<string | number, unknown>>(_options: Partial<FetchOptions> & {
61
87
  url: string;
62
- }): Promise<Response>;
88
+ }): Promise<ResponseType>;
63
89
  /**
64
- * It fetches a JSON file from a URL, and returns the parsed data.
90
+ * It's a wrapper around the browser's `fetch` function that adds retry pattern, timeout, cacheStrategy,
91
+ * remove duplicates, etc.
65
92
  *
66
93
  * Example:
67
94
  *
68
95
  * ```ts
69
- * const productList = await getJson<ProductResponse>({
96
+ * const response = await fetch({
70
97
  * url: '/api/products',
71
98
  * queryParameters: {limit: 10},
72
- * timeout: 5_000,
99
+ * timeout: 10_000,
73
100
  * retry: 3,
74
101
  * cacheStrategy: 'stale_while_revalidate',
102
+ * cacheDuplicate: 'auto',
75
103
  * });
76
104
  * ```
77
105
  */
78
- export declare function getJson<ResponseType extends Record<string | number, unknown>>(options: Partial<FetchOptions> & {
106
+ export declare function fetch(_options: Partial<FetchOptions> & {
79
107
  url: string;
80
- }): Promise<ResponseType>;
108
+ }): Promise<Response>;
81
109
  //# sourceMappingURL=fetch.d.ts.map
package/fetch.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["src/fetch.ts"],"names":[],"mappings":"AASA,OAAO,CAAC,MAAM,CAAC;IAEb,UAAU,eAAe;QACvB,KAAK,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;KAC9B;CACF;AAED,oBAAY,aAAa,GAAG,cAAc,GAAG,eAAe,GAAG,Y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EZ;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;;;OAIG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;;;OAIG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;;;OAIG;IACF,UAAU,EAAE,MAAM,CAAC;IAEpB;;;;;;;;;OASG;IACH,eAAe,EAAE,cAAc,CAAC;IAEhC;;;;;;;;;;OAUG;IACH,aAAa,EAAE,aAAa,CAAC;IAE7B;;OAEG;IACH,kBAAkB,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,IAAI,CAAC;IAElD;;OAEG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,CAAC;IAE5C;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC;CAC7D;AAOD;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,OAAO,CAAC,YAAY,SAAS,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,EAC/E,QAAQ,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG;IAAC,GAAG,EAAE,MAAM,CAAA;CAAC,GAChD,OAAO,CAAC,YAAY,CAAC,CA6BvB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG;IAAC,GAAG,EAAE,MAAM,CAAA;CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAIxF"}
package/fetch.js CHANGED
@@ -4,10 +4,53 @@ alwatrRegisteredList.push({
4
4
  name: '@alwatr/fetch',
5
5
  version: '{{ALWATR_VERSION}}',
6
6
  });
7
- let cacheStorage;
7
+ let alwatrCacheStorage;
8
8
  const cacheSupported = 'caches' in self;
9
+ const duplicateRequestStorage = {};
9
10
  /**
10
- * It's a wrapper around the browser's `fetch` function that adds retry pattern with timeout and cacheStrategy.
11
+ * It fetches a JSON file from a URL, and returns the parsed data.
12
+ *
13
+ * Example:
14
+ *
15
+ * ```ts
16
+ * const productList = await getJson<ProductResponse>({
17
+ * url: '/api/products',
18
+ * queryParameters: {limit: 10},
19
+ * timeout: 10_000,
20
+ * retry: 3,
21
+ * cacheStrategy: 'stale_while_revalidate',
22
+ * cacheDuplicate: 'auto',
23
+ * });
24
+ * ```
25
+ */
26
+ export async function getJson(_options) {
27
+ const options = _processOptions(_options);
28
+ logger.logMethodArgs('getJson', { options });
29
+ const response = await _handleRemoveDuplicate(options);
30
+ let data;
31
+ try {
32
+ if (!response.ok) {
33
+ throw new Error('fetch_nok');
34
+ }
35
+ data = (await response.json());
36
+ }
37
+ catch (err) {
38
+ logger.accident('getJson', 'response_json', 'response json error', {
39
+ retry: options.retry,
40
+ err,
41
+ });
42
+ if (options.retry > 1) {
43
+ data = await getJson(options);
44
+ }
45
+ else {
46
+ throw err;
47
+ }
48
+ }
49
+ return data;
50
+ }
51
+ /**
52
+ * It's a wrapper around the browser's `fetch` function that adds retry pattern, timeout, cacheStrategy,
53
+ * remove duplicates, etc.
11
54
  *
12
55
  * Example:
13
56
  *
@@ -15,29 +58,104 @@ const cacheSupported = 'caches' in self;
15
58
  * const response = await fetch({
16
59
  * url: '/api/products',
17
60
  * queryParameters: {limit: 10},
18
- * timeout: 5_000,
61
+ * timeout: 10_000,
19
62
  * retry: 3,
20
63
  * cacheStrategy: 'stale_while_revalidate',
64
+ * cacheDuplicate: 'auto',
21
65
  * });
22
66
  * ```
23
67
  */
24
- export async function fetch(_options) {
68
+ export function fetch(_options) {
25
69
  const options = _processOptions(_options);
26
70
  logger.logMethodArgs('fetch', { options });
71
+ return _handleRemoveDuplicate(options);
72
+ }
73
+ /**
74
+ * Process fetch options and set defaults, etc.
75
+ */
76
+ function _processOptions(options) {
77
+ options.method = options.method != null ? options.method.toUpperCase() : 'GET';
78
+ options.window ?? (options.window = null);
79
+ options.timeout ?? (options.timeout = 10000);
80
+ options.retry ?? (options.retry = 3);
81
+ options.retryDelay ?? (options.retryDelay = 1000);
82
+ options.cacheStrategy ?? (options.cacheStrategy = 'network_only');
83
+ options.removeDuplicate ?? (options.removeDuplicate = 'never');
84
+ if (options.cacheStrategy !== 'network_only' && cacheSupported !== true) {
85
+ logger.accident('fetch', 'fetch_cache_strategy_ignore', 'Cache storage not support in this browser', {
86
+ cacheSupported,
87
+ });
88
+ options.cacheStrategy = 'network_only';
89
+ }
90
+ if (options.removeDuplicate === 'auto') {
91
+ options.removeDuplicate = cacheSupported ? 'until_load' : 'always';
92
+ }
93
+ if (options.url.lastIndexOf('?') === -1 && options.queryParameters != null) {
94
+ // prettier-ignore
95
+ const queryArray = Object
96
+ .keys(options.queryParameters)
97
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
98
+ .map((key) => `${key}=${String(options.queryParameters[key])}`);
99
+ if (queryArray.length > 0) {
100
+ options.url += '?' + queryArray.join('&');
101
+ }
102
+ }
103
+ if (options.body != null && options.bodyJson != null) {
104
+ options.body = JSON.stringify(options.bodyJson);
105
+ options.headers = {
106
+ ...options.headers,
107
+ 'Content-Type': 'application/json',
108
+ };
109
+ }
110
+ return options;
111
+ }
112
+ /**
113
+ * Handle Remove Duplicates over `_handleCacheStrategy`.
114
+ */
115
+ async function _handleRemoveDuplicate(options) {
116
+ if (options.removeDuplicate === 'never')
117
+ return _handleCacheStrategy(options);
118
+ logger.logMethod('_handleRemoveDuplicate');
119
+ const cacheKey = `[${options.method}] ${options.url}`;
120
+ const firstRequest = duplicateRequestStorage[cacheKey] == null;
121
+ // We must cache fetch promise without await for handle other parallel requests.
122
+ duplicateRequestStorage[cacheKey] ?? (duplicateRequestStorage[cacheKey] = _handleCacheStrategy(options));
123
+ try {
124
+ // For all requests need to await for clone responses.
125
+ const response = await duplicateRequestStorage[cacheKey];
126
+ if (firstRequest === true) {
127
+ if (response.ok !== true || options.removeDuplicate === 'until_load') {
128
+ delete duplicateRequestStorage[cacheKey];
129
+ }
130
+ }
131
+ return response.clone();
132
+ }
133
+ catch (err) {
134
+ // clean cache on any error.
135
+ delete duplicateRequestStorage[cacheKey];
136
+ throw err;
137
+ }
138
+ }
139
+ /**
140
+ * Handle Cache Strategy over `_handleRetryPattern`.
141
+ */
142
+ async function _handleCacheStrategy(options) {
27
143
  if (options.cacheStrategy === 'network_only') {
28
- return _fetch(options);
144
+ return _handleRetryPattern(options);
29
145
  }
30
146
  // else handle cache strategies!
31
- if (cacheStorage == null) {
32
- cacheStorage = await caches.open(options.cacheStorageName);
147
+ logger.logMethod('_handleCacheStrategy');
148
+ if (alwatrCacheStorage == null && options.cacheStorageName == null) {
149
+ alwatrCacheStorage = await caches.open('alwatr_fetch_cache');
33
150
  }
151
+ const cacheStorage = options.cacheStorageName != null ? await caches.open(options.cacheStorageName) : alwatrCacheStorage;
34
152
  const request = new Request(options.url, options);
35
153
  switch (options.cacheStrategy) {
36
154
  case 'cache_first': {
37
155
  const cachedResponse = await cacheStorage.match(request);
38
156
  if (cachedResponse != null)
39
157
  return cachedResponse;
40
- const response = await _fetch(options);
158
+ const response = await _handleRetryPattern(options);
41
159
  if (response.ok) {
42
160
  cacheStorage.put(request, response.clone());
43
161
  }
@@ -51,7 +169,7 @@ export async function fetch(_options) {
51
169
  }
52
170
  case 'network_first': {
53
171
  try {
54
- const networkResponse = await _fetch(options);
172
+ const networkResponse = await _handleRetryPattern(options);
55
173
  if (networkResponse.ok) {
56
174
  cacheStorage.put(request, networkResponse.clone());
57
175
  }
@@ -66,148 +184,90 @@ export async function fetch(_options) {
66
184
  }
67
185
  case 'stale_while_revalidate': {
68
186
  const cachedResponse = await cacheStorage.match(request);
69
- const fetchedResponsePromise = _fetch(options).then((networkResponse) => {
187
+ const fetchedResponsePromise = _handleRetryPattern(options);
188
+ fetchedResponsePromise.then((networkResponse) => {
70
189
  if (networkResponse.ok) {
71
190
  cacheStorage.put(request, networkResponse.clone());
191
+ if (cachedResponse != null && typeof options.revalidateCallback === 'function') {
192
+ options.revalidateCallback(networkResponse);
193
+ }
72
194
  }
73
- return networkResponse;
74
195
  });
75
196
  return cachedResponse || fetchedResponsePromise;
76
197
  }
77
198
  default: {
78
- return _fetch(options);
79
- }
80
- }
81
- }
82
- function _processOptions(options) {
83
- options.method ?? (options.method = 'GET');
84
- options.window ?? (options.window = null);
85
- options.timeout ?? (options.timeout = 5000);
86
- options.retry ?? (options.retry = 3);
87
- options.cacheStrategy ?? (options.cacheStrategy = 'network_only');
88
- options.cacheStorageName ?? (options.cacheStorageName = 'alwatr_fetch_cache');
89
- if (options.cacheStrategy !== 'network_only' && cacheSupported !== true) {
90
- logger.accident('fetch', 'fetch_cache_strategy_ignore', 'Cache storage not support in this browser', {
91
- cacheSupported,
92
- });
93
- options.cacheStrategy = 'network_only';
94
- }
95
- if (options.url.lastIndexOf('?') === -1 && options.queryParameters != null) {
96
- // prettier-ignore
97
- const queryArray = Object
98
- .keys(options.queryParameters)
99
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
100
- .map((key) => `${key}=${String(options.queryParameters[key])}`);
101
- if (queryArray.length > 0) {
102
- options.url += '?' + queryArray.join('&');
199
+ return _handleRetryPattern(options);
103
200
  }
104
201
  }
105
- if (options.body != null && options.bodyJson != null) {
106
- options.body = JSON.stringify(options.bodyJson);
107
- options.headers = {
108
- ...options.headers,
109
- 'Content-Type': 'application/json',
110
- };
111
- }
112
- return options;
113
202
  }
114
203
  /**
115
- * It's a wrapper around the browser's `fetch` function that adds retry pattern with timeout.
204
+ * Handle retry pattern over `_handleTimeout`.
116
205
  */
117
- async function _fetch(options) {
118
- logger.logMethodArgs('_fetch', { options });
119
- // @TODO: AbortController polyfill
120
- const abortController = new AbortController();
206
+ async function _handleRetryPattern(options) {
207
+ if (!(options.retry >= 1))
208
+ return _handleTimeout(options);
209
+ logger.logMethod('_handleRetryPattern');
121
210
  const externalAbortSignal = options.signal;
122
- options.signal = abortController.signal;
123
- let timedOut = false;
124
- const timeoutId = setTimeout(() => {
125
- abortController.abort('fetch_timeout');
126
- timedOut = true;
127
- }, options.timeout);
128
- if (externalAbortSignal != null) {
129
- // Respect external abort signal
130
- externalAbortSignal.addEventListener('abort', () => {
131
- abortController.abort(`external abort signal: ${externalAbortSignal.reason}`);
132
- clearTimeout(timeoutId);
133
- });
134
- }
135
- abortController.signal.addEventListener('abort', () => {
136
- logger.incident('fetch', 'fetch_abort_signal', 'fetch abort signal received', {
137
- reason: abortController.signal.reason,
138
- });
139
- });
140
- const retryFetch = () => {
141
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
211
+ const retryFetch = async () => {
142
212
  options.retry--;
143
213
  options.signal = externalAbortSignal;
144
- return fetch(options);
214
+ await _wait(options.retryDelay);
215
+ return _handleCacheStrategy(options); // maybe cache updated by another request ;)
145
216
  };
146
217
  try {
147
- // @TODO: browser fetch polyfill
148
- const response = await window.fetch(options.url, options);
149
- clearTimeout(timeoutId);
150
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
218
+ const response = await _handleTimeout(options);
151
219
  if (options.retry > 1 && response.status >= 502 && response.status <= 504) {
152
220
  logger.accident('fetch', 'fetch_not_valid', 'fetch not valid and retry', {
153
221
  response,
154
222
  });
155
223
  return retryFetch();
156
224
  }
225
+ // else
157
226
  return response;
158
227
  }
159
228
  catch (reason) {
160
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
161
- if (timedOut && options.retry > 1) {
229
+ if (reason?.message === 'fetch_timeout' && options.retry > 1) {
162
230
  logger.incident('fetch', 'fetch_timeout', 'fetch timeout and retry', {
163
231
  reason,
164
232
  });
165
233
  return retryFetch();
166
234
  }
167
- else {
168
- clearTimeout(timeoutId);
169
- throw reason;
170
- }
235
+ // else
236
+ throw reason;
171
237
  }
172
238
  }
173
239
  /**
174
- * It fetches a JSON file from a URL, and returns the parsed data.
175
- *
176
- * Example:
177
- *
178
- * ```ts
179
- * const productList = await getJson<ProductResponse>({
180
- * url: '/api/products',
181
- * queryParameters: {limit: 10},
182
- * timeout: 5_000,
183
- * retry: 3,
184
- * cacheStrategy: 'stale_while_revalidate',
185
- * });
186
- * ```
240
+ * It's a wrapper around the browser's `fetch` with timeout.
187
241
  */
188
- export async function getJson(options) {
189
- logger.logMethodArgs('getJson', { options });
190
- const response = await fetch(options);
191
- let data;
192
- try {
193
- if (!response.ok) {
194
- throw new Error('fetch_nok');
242
+ function _handleTimeout(options) {
243
+ logger.logMethod('_handleTimeout');
244
+ return new Promise((resolved, reject) => {
245
+ // @TODO: AbortController polyfill
246
+ const abortController = new AbortController();
247
+ const externalAbortSignal = options.signal;
248
+ options.signal = abortController.signal;
249
+ const timeoutId = setTimeout(() => {
250
+ reject(new Error('fetch_timeout'));
251
+ abortController.abort('fetch_timeout');
252
+ }, options.timeout);
253
+ if (externalAbortSignal != null) {
254
+ // Respect external abort signal
255
+ externalAbortSignal.addEventListener('abort', () => {
256
+ abortController.abort(`external abort signal: ${externalAbortSignal.reason}`);
257
+ clearTimeout(timeoutId);
258
+ });
195
259
  }
196
- data = (await response.json());
197
- }
198
- catch (err) {
199
- logger.accident('getJson', 'response_json', 'response json error', {
200
- retry: options.retry,
201
- err,
260
+ abortController.signal.addEventListener('abort', () => {
261
+ logger.incident('fetch', 'fetch_abort_signal', 'fetch abort signal received', {
262
+ reason: abortController.signal.reason,
263
+ });
202
264
  });
203
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
204
- if (options.retry > 1) {
205
- data = await getJson(options);
206
- }
207
- else {
208
- throw err;
209
- }
210
- }
211
- return data;
265
+ window
266
+ .fetch(options.url, options)
267
+ .then((response) => resolved(response))
268
+ .catch((reason) => reject(reason))
269
+ .finally(() => clearTimeout(timeoutId));
270
+ });
212
271
  }
272
+ const _wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
213
273
  //# sourceMappingURL=fetch.js.map
package/fetch.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"fetch.js","sourceRoot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AC,CAAC;QACzC,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;QAEpB,IAAI,mBAAmB,IAAI,IAAI,EAAE;YAC/B,gCAAgC;YAChC,mBAAmB,CAAC,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE;gBACjD,eAAe,CAAC,KAAK,CAAC,0BAA0B,mBAAmB,CAAC,MAAM,EAAE,CAAC,CAAC;gBAC9E,YAAY,CAAC,SAAS,CAAC,CAAC;YAC1B,CAAC,CAAC,CAAC;SACJ;QAED,eAAe,CAAC,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE;YACpD,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,oBAAoB,EAAE,6BAA6B,EAAE;gBAC5E,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC,MAAM;aACtC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,MAAM;aACD,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC;aAC3B,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;aACtC,KAAK,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;aACjC,OAAO,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC,CAAC;IAC9C,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,KAAK,GAAG,CAAC,EAAU,EAAiB,EAAE,CAAC,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alwatr/fetch",
3
- "version": "0.18.0",
3
+ "version": "0.20.0",
4
4
  "description": "Enhanced fetch API with cache strategy, retry pattern, timeout, helper methods and enhanced types written in tiny TypeScript, ES module.",
5
5
  "keywords": [
6
6
  "fetch",
@@ -34,8 +34,8 @@
34
34
  "url": "https://github.com/AliMD/alwatr/issues"
35
35
  },
36
36
  "dependencies": {
37
- "@alwatr/logger": "^0.18.0",
38
- "tslib": "^2.3.1"
37
+ "@alwatr/logger": "^0.20.0",
38
+ "tslib": "^2.4.1"
39
39
  },
40
- "gitHead": "a6f75b381a758849b514ea0d59eec6a3b3444008"
40
+ "gitHead": "537f53e355475ae6ba652d4eb2c6d26fe77be12c"
41
41
  }