@naturalcycles/js-lib 14.131.2 → 14.132.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.
@@ -30,26 +30,25 @@ class Fetcher {
30
30
  this.cfg = this.normalizeCfg(cfg);
31
31
  // Dynamically create all helper methods
32
32
  http_model_1.HTTP_METHODS.forEach(method => {
33
- // mode=void
34
- this[`${method}Void`] = async (url, opt) => {
33
+ const m = method.toLowerCase();
34
+ this[`${m}Void`] = async (url, opt) => {
35
35
  return await this.fetch(url, {
36
36
  method,
37
37
  mode: 'void',
38
38
  ...opt,
39
39
  });
40
40
  };
41
- if (method === 'head')
41
+ if (method === 'HEAD')
42
42
  return // mode=text
43
43
  ;
44
- this[`${method}Text`] = async (url, opt) => {
44
+ this[`${m}Text`] = async (url, opt) => {
45
45
  return await this.fetch(url, {
46
46
  method,
47
47
  mode: 'text',
48
48
  ...opt,
49
49
  });
50
50
  };
51
- // Default mode=json, but overridable
52
- this[method] = async (url, opt) => {
51
+ this[m] = async (url, opt) => {
53
52
  return await this.fetch(url, {
54
53
  method,
55
54
  mode: 'json',
@@ -118,7 +117,7 @@ class Fetcher {
118
117
  };
119
118
  const fullUrl = new URL(req.url);
120
119
  const shortUrl = this.getShortUrl(fullUrl);
121
- const signature = [method.toUpperCase(), shortUrl].join(' ');
120
+ const signature = [method, shortUrl].join(' ');
122
121
  /* eslint-disable no-await-in-loop */
123
122
  while (!res.retryStatus.retryStopped) {
124
123
  const started = Date.now();
@@ -263,7 +262,7 @@ class Fetcher {
263
262
  shouldRetry(res) {
264
263
  const { retryPost, retry4xx, retry5xx } = res.req;
265
264
  const { method } = res.req.init;
266
- if (method === 'post' && !retryPost)
265
+ if (method === 'POST' && !retryPost)
267
266
  return false;
268
267
  const { statusFamily } = res;
269
268
  const statusCode = res.fetchResponse?.status || 0;
@@ -336,7 +335,7 @@ class Fetcher {
336
335
  logWithSearchParams: true,
337
336
  retry: { ...defRetryOptions },
338
337
  init: {
339
- method: cfg.method || 'get',
338
+ method: cfg.method || 'GET',
340
339
  headers: cfg.headers || {},
341
340
  credentials: cfg.credentials,
342
341
  },
@@ -1,3 +1,3 @@
1
- export type HttpMethod = 'get' | 'post' | 'put' | 'patch' | 'delete' | 'head';
1
+ export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD';
2
2
  export type HttpStatusFamily = 5 | 4 | 3 | 2 | 1;
3
3
  export declare const HTTP_METHODS: HttpMethod[];
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HTTP_METHODS = void 0;
4
- exports.HTTP_METHODS = ['get', 'post', 'put', 'patch', 'delete', 'head'];
4
+ exports.HTTP_METHODS = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD'];
@@ -28,18 +28,17 @@ export class Fetcher {
28
28
  this.cfg = this.normalizeCfg(cfg);
29
29
  // Dynamically create all helper methods
30
30
  HTTP_METHODS.forEach(method => {
31
- // mode=void
32
- this[`${method}Void`] = async (url, opt) => {
31
+ const m = method.toLowerCase();
32
+ this[`${m}Void`] = async (url, opt) => {
33
33
  return await this.fetch(url, Object.assign({ method, mode: 'void' }, opt));
34
34
  };
35
- if (method === 'head')
35
+ if (method === 'HEAD')
36
36
  return // mode=text
37
37
  ;
38
- this[`${method}Text`] = async (url, opt) => {
38
+ this[`${m}Text`] = async (url, opt) => {
39
39
  return await this.fetch(url, Object.assign({ method, mode: 'text' }, opt));
40
40
  };
41
- // Default mode=json, but overridable
42
- this[method] = async (url, opt) => {
41
+ this[m] = async (url, opt) => {
43
42
  return await this.fetch(url, Object.assign({ method, mode: 'json' }, opt));
44
43
  };
45
44
  });
@@ -126,7 +125,7 @@ export class Fetcher {
126
125
  };
127
126
  const fullUrl = new URL(req.url);
128
127
  const shortUrl = this.getShortUrl(fullUrl);
129
- const signature = [method.toUpperCase(), shortUrl].join(' ');
128
+ const signature = [method, shortUrl].join(' ');
130
129
  /* eslint-disable no-await-in-loop */
131
130
  while (!res.retryStatus.retryStopped) {
132
131
  const started = Date.now();
@@ -302,7 +301,7 @@ export class Fetcher {
302
301
  var _a;
303
302
  const { retryPost, retry4xx, retry5xx } = res.req;
304
303
  const { method } = res.req.init;
305
- if (method === 'post' && !retryPost)
304
+ if (method === 'POST' && !retryPost)
306
305
  return false;
307
306
  const { statusFamily } = res;
308
307
  const statusCode = ((_a = res.fetchResponse) === null || _a === void 0 ? void 0 : _a.status) || 0;
@@ -377,7 +376,7 @@ export class Fetcher {
377
376
  logWithSearchParams: true,
378
377
  retry: Object.assign({}, defRetryOptions),
379
378
  init: {
380
- method: cfg.method || 'get',
379
+ method: cfg.method || 'GET',
381
380
  headers: cfg.headers || {},
382
381
  credentials: cfg.credentials,
383
382
  },
@@ -1 +1 @@
1
- export const HTTP_METHODS = ['get', 'post', 'put', 'patch', 'delete', 'head'];
1
+ export const HTTP_METHODS = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD'];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/js-lib",
3
- "version": "14.131.2",
3
+ "version": "14.132.0",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "build-prod": "build-prod-esm-cjs",
@@ -51,8 +51,10 @@ export class Fetcher {
51
51
 
52
52
  // Dynamically create all helper methods
53
53
  HTTP_METHODS.forEach(method => {
54
+ const m = method.toLowerCase()
55
+
54
56
  // mode=void
55
- this[`${method}Void`] = async (url: string, opt?: FetcherOptions): Promise<void> => {
57
+ ;(this as any)[`${m}Void`] = async (url: string, opt?: FetcherOptions): Promise<void> => {
56
58
  return await this.fetch<void>(url, {
57
59
  method,
58
60
  mode: 'void',
@@ -60,11 +62,8 @@ export class Fetcher {
60
62
  })
61
63
  }
62
64
 
63
- if (method === 'head') return // mode=text
64
- ;(this as any)[`${method}Text`] = async (
65
- url: string,
66
- opt?: FetcherOptions,
67
- ): Promise<string> => {
65
+ if (method === 'HEAD') return // mode=text
66
+ ;(this as any)[`${m}Text`] = async (url: string, opt?: FetcherOptions): Promise<string> => {
68
67
  return await this.fetch<string>(url, {
69
68
  method,
70
69
  mode: 'text',
@@ -73,7 +72,7 @@ export class Fetcher {
73
72
  }
74
73
 
75
74
  // Default mode=json, but overridable
76
- this[method] = async <T = unknown>(url: string, opt?: FetcherOptions): Promise<T> => {
75
+ ;(this as any)[m] = async <T = unknown>(url: string, opt?: FetcherOptions): Promise<T> => {
77
76
  return await this.fetch<T>(url, {
78
77
  method,
79
78
  mode: 'json',
@@ -181,7 +180,7 @@ export class Fetcher {
181
180
 
182
181
  const fullUrl = new URL(req.url)
183
182
  const shortUrl = this.getShortUrl(fullUrl)
184
- const signature = [method.toUpperCase(), shortUrl].join(' ')
183
+ const signature = [method, shortUrl].join(' ')
185
184
 
186
185
  /* eslint-disable no-await-in-loop */
187
186
  while (!res.retryStatus.retryStopped) {
@@ -347,7 +346,7 @@ export class Fetcher {
347
346
  private shouldRetry(res: FetcherResponse): boolean {
348
347
  const { retryPost, retry4xx, retry5xx } = res.req
349
348
  const { method } = res.req.init
350
- if (method === 'post' && !retryPost) return false
349
+ if (method === 'POST' && !retryPost) return false
351
350
  const { statusFamily } = res
352
351
  const statusCode = res.fetchResponse?.status || 0
353
352
  if (statusFamily === 5 && !retry5xx) return false
@@ -421,7 +420,7 @@ export class Fetcher {
421
420
  logWithSearchParams: true,
422
421
  retry: { ...defRetryOptions },
423
422
  init: {
424
- method: cfg.method || 'get',
423
+ method: cfg.method || 'GET',
425
424
  headers: cfg.headers || {},
426
425
  credentials: cfg.credentials,
427
426
  },
@@ -1,5 +1,5 @@
1
- export type HttpMethod = 'get' | 'post' | 'put' | 'patch' | 'delete' | 'head'
1
+ export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD'
2
2
 
3
3
  export type HttpStatusFamily = 5 | 4 | 3 | 2 | 1
4
4
 
5
- export const HTTP_METHODS: HttpMethod[] = ['get', 'post', 'put', 'patch', 'delete', 'head']
5
+ export const HTTP_METHODS: HttpMethod[] = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD']