@naturalcycles/js-lib 14.130.1 → 14.131.1

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.
@@ -33,9 +33,9 @@ class Fetcher {
33
33
  // mode=void
34
34
  this[`${method}Void`] = async (url, opt) => {
35
35
  return await this.fetch(url, {
36
- ...opt,
37
36
  method,
38
37
  mode: 'void',
38
+ ...opt,
39
39
  });
40
40
  };
41
41
  if (method === 'head')
@@ -43,17 +43,17 @@ class Fetcher {
43
43
  ;
44
44
  this[`${method}Text`] = async (url, opt) => {
45
45
  return await this.fetch(url, {
46
- ...opt,
47
46
  method,
48
47
  mode: 'text',
48
+ ...opt,
49
49
  });
50
50
  };
51
- // mode=json
51
+ // Default mode=json, but overridable
52
52
  this[method] = async (url, opt) => {
53
53
  return await this.fetch(url, {
54
- ...opt,
55
54
  method,
56
55
  mode: 'json',
56
+ ...opt,
57
57
  });
58
58
  };
59
59
  });
@@ -173,6 +173,12 @@ class Fetcher {
173
173
  else if (mode === 'text') {
174
174
  res.body = res.fetchResponse.body ? await res.fetchResponse.text() : '';
175
175
  }
176
+ else if (mode === 'arrayBuffer') {
177
+ res.body = res.fetchResponse.body ? await res.fetchResponse.arrayBuffer() : {};
178
+ }
179
+ else if (mode === 'blob') {
180
+ res.body = res.fetchResponse.body ? await res.fetchResponse.blob() : {};
181
+ }
176
182
  clearTimeout(timeout);
177
183
  res.retryStatus.retryStopped = true;
178
184
  // res.err can happen on JSON.parse error
@@ -148,4 +148,4 @@ export interface FetcherErrorResponse<BODY = unknown> {
148
148
  retryStatus: FetcherRetryStatus;
149
149
  }
150
150
  export type FetcherResponse<BODY = unknown> = FetcherSuccessResponse<BODY> | FetcherErrorResponse<BODY>;
151
- export type FetcherMode = 'json' | 'text' | 'void';
151
+ export type FetcherMode = 'json' | 'text' | 'void' | 'arrayBuffer' | 'blob';
@@ -30,17 +30,17 @@ export class Fetcher {
30
30
  HTTP_METHODS.forEach(method => {
31
31
  // mode=void
32
32
  this[`${method}Void`] = async (url, opt) => {
33
- return await this.fetch(url, Object.assign(Object.assign({}, opt), { method, mode: 'void' }));
33
+ return await this.fetch(url, Object.assign({ method, mode: 'void' }, opt));
34
34
  };
35
35
  if (method === 'head')
36
36
  return // mode=text
37
37
  ;
38
38
  this[`${method}Text`] = async (url, opt) => {
39
- return await this.fetch(url, Object.assign(Object.assign({}, opt), { method, mode: 'text' }));
39
+ return await this.fetch(url, Object.assign({ method, mode: 'text' }, opt));
40
40
  };
41
- // mode=json
41
+ // Default mode=json, but overridable
42
42
  this[method] = async (url, opt) => {
43
- return await this.fetch(url, Object.assign(Object.assign({}, opt), { method, mode: 'json' }));
43
+ return await this.fetch(url, Object.assign({ method, mode: 'json' }, opt));
44
44
  };
45
45
  });
46
46
  }
@@ -181,6 +181,12 @@ export class Fetcher {
181
181
  else if (mode === 'text') {
182
182
  res.body = res.fetchResponse.body ? await res.fetchResponse.text() : '';
183
183
  }
184
+ else if (mode === 'arrayBuffer') {
185
+ res.body = res.fetchResponse.body ? await res.fetchResponse.arrayBuffer() : {};
186
+ }
187
+ else if (mode === 'blob') {
188
+ res.body = res.fetchResponse.body ? await res.fetchResponse.blob() : {};
189
+ }
184
190
  clearTimeout(timeout);
185
191
  res.retryStatus.retryStopped = true;
186
192
  // res.err can happen on JSON.parse error
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/js-lib",
3
- "version": "14.130.1",
3
+ "version": "14.131.1",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "build-prod": "build-prod-esm-cjs",
@@ -178,4 +178,4 @@ export type FetcherResponse<BODY = unknown> =
178
178
  | FetcherSuccessResponse<BODY>
179
179
  | FetcherErrorResponse<BODY>
180
180
 
181
- export type FetcherMode = 'json' | 'text' | 'void'
181
+ export type FetcherMode = 'json' | 'text' | 'void' | 'arrayBuffer' | 'blob'
@@ -54,9 +54,9 @@ export class Fetcher {
54
54
  // mode=void
55
55
  this[`${method}Void`] = async (url: string, opt?: FetcherOptions): Promise<void> => {
56
56
  return await this.fetch<void>(url, {
57
- ...opt,
58
57
  method,
59
58
  mode: 'void',
59
+ ...opt,
60
60
  })
61
61
  }
62
62
 
@@ -66,18 +66,18 @@ export class Fetcher {
66
66
  opt?: FetcherOptions,
67
67
  ): Promise<string> => {
68
68
  return await this.fetch<string>(url, {
69
- ...opt,
70
69
  method,
71
70
  mode: 'text',
71
+ ...opt,
72
72
  })
73
73
  }
74
74
 
75
- // mode=json
75
+ // Default mode=json, but overridable
76
76
  this[method] = async <T = unknown>(url: string, opt?: FetcherOptions): Promise<T> => {
77
77
  return await this.fetch<T>(url, {
78
- ...opt,
79
78
  method,
80
79
  mode: 'json',
80
+ ...opt,
81
81
  })
82
82
  }
83
83
  })
@@ -237,6 +237,10 @@ export class Fetcher {
237
237
  }
238
238
  } else if (mode === 'text') {
239
239
  res.body = res.fetchResponse.body ? await res.fetchResponse.text() : ''
240
+ } else if (mode === 'arrayBuffer') {
241
+ res.body = res.fetchResponse.body ? await res.fetchResponse.arrayBuffer() : {}
242
+ } else if (mode === 'blob') {
243
+ res.body = res.fetchResponse.body ? await res.fetchResponse.blob() : {}
240
244
  }
241
245
 
242
246
  clearTimeout(timeout)