@naturalcycles/js-lib 14.139.1 → 14.139.3

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.
@@ -51,7 +51,7 @@ class LocalDate {
51
51
  if (d instanceof LocalDate)
52
52
  return d;
53
53
  // const [year, month, day] = d.slice(0, 10).split('-').map(Number)
54
- const matches = DATE_REGEX.exec(d.slice(0, 10));
54
+ const matches = typeof d === 'string' && DATE_REGEX.exec(d.slice(0, 10));
55
55
  if (!matches)
56
56
  return null;
57
57
  const year = Number(matches[1]);
@@ -60,6 +60,10 @@ class LocalTime {
60
60
  else if (typeof d === 'number') {
61
61
  date = new Date(d * 1000);
62
62
  }
63
+ else if (typeof d !== 'string') {
64
+ // unexpected type, e.g Function or something
65
+ return null;
66
+ }
63
67
  else {
64
68
  date = new Date(d.slice(0, 19));
65
69
  }
@@ -119,7 +119,6 @@ class Fetcher {
119
119
  },
120
120
  signature,
121
121
  };
122
- /* eslint-disable no-await-in-loop */
123
122
  while (!res.retryStatus.retryStopped) {
124
123
  const started = Date.now();
125
124
  if (this.cfg.logRequest) {
@@ -139,6 +138,8 @@ class Fetcher {
139
138
  // For example, CORS error would result in "TypeError: failed to fetch" here
140
139
  res.err = err;
141
140
  res.ok = false;
141
+ // important to set it to undefined, otherwise it can keep the previous value (from previous try)
142
+ res.fetchResponse = undefined;
142
143
  }
143
144
  res.statusFamily = this.getStatusFamily(res);
144
145
  if (res.fetchResponse?.ok) {
@@ -25,7 +25,7 @@ async function pRetry(fn, opt = {}) {
25
25
  const fname = name || fn.name || 'pRetry function';
26
26
  let delay = initialDelay;
27
27
  let attempt = 0;
28
- /* eslint-disable no-await-in-loop, no-constant-condition */
28
+ /* eslint-disable no-constant-condition */
29
29
  while (true) {
30
30
  const started = Date.now();
31
31
  try {
package/dist/seq/seq.js CHANGED
@@ -149,7 +149,6 @@ function _seq(initialValue, nextFn) {
149
149
  return Sequence.create(initialValue, nextFn);
150
150
  }
151
151
  exports._seq = _seq;
152
- /* eslint-disable no-await-in-loop */
153
152
  /**
154
153
  * Experimental.
155
154
  * Feasibility to be proven.
@@ -48,7 +48,7 @@ export class LocalDate {
48
48
  if (d instanceof LocalDate)
49
49
  return d;
50
50
  // const [year, month, day] = d.slice(0, 10).split('-').map(Number)
51
- const matches = DATE_REGEX.exec(d.slice(0, 10));
51
+ const matches = typeof d === 'string' && DATE_REGEX.exec(d.slice(0, 10));
52
52
  if (!matches)
53
53
  return null;
54
54
  const year = Number(matches[1]);
@@ -57,6 +57,10 @@ export class LocalTime {
57
57
  else if (typeof d === 'number') {
58
58
  date = new Date(d * 1000);
59
59
  }
60
+ else if (typeof d !== 'string') {
61
+ // unexpected type, e.g Function or something
62
+ return null;
63
+ }
60
64
  else {
61
65
  date = new Date(d.slice(0, 19));
62
66
  }
@@ -127,7 +127,6 @@ export class Fetcher {
127
127
  },
128
128
  signature,
129
129
  };
130
- /* eslint-disable no-await-in-loop */
131
130
  while (!res.retryStatus.retryStopped) {
132
131
  const started = Date.now();
133
132
  if (this.cfg.logRequest) {
@@ -147,6 +146,8 @@ export class Fetcher {
147
146
  // For example, CORS error would result in "TypeError: failed to fetch" here
148
147
  res.err = err;
149
148
  res.ok = false;
149
+ // important to set it to undefined, otherwise it can keep the previous value (from previous try)
150
+ res.fetchResponse = undefined;
150
151
  }
151
152
  res.statusFamily = this.getStatusFamily(res);
152
153
  if ((_g = res.fetchResponse) === null || _g === void 0 ? void 0 : _g.ok) {
@@ -21,7 +21,7 @@ export async function pRetry(fn, opt = {}) {
21
21
  const fname = name || fn.name || 'pRetry function';
22
22
  let delay = initialDelay;
23
23
  let attempt = 0;
24
- /* eslint-disable no-await-in-loop, no-constant-condition */
24
+ /* eslint-disable no-constant-condition */
25
25
  while (true) {
26
26
  const started = Date.now();
27
27
  try {
@@ -144,7 +144,6 @@ export class Sequence {
144
144
  export function _seq(initialValue, nextFn) {
145
145
  return Sequence.create(initialValue, nextFn);
146
146
  }
147
- /* eslint-disable no-await-in-loop */
148
147
  /**
149
148
  * Experimental.
150
149
  * Feasibility to be proven.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/js-lib",
3
- "version": "14.139.1",
3
+ "version": "14.139.3",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "build-prod": "build-prod-esm-cjs",
@@ -69,7 +69,7 @@ export class LocalDate {
69
69
  if (d instanceof LocalDate) return d
70
70
 
71
71
  // const [year, month, day] = d.slice(0, 10).split('-').map(Number)
72
- const matches = DATE_REGEX.exec(d.slice(0, 10))
72
+ const matches = typeof (d as any) === 'string' && DATE_REGEX.exec(d.slice(0, 10))
73
73
  if (!matches) return null
74
74
 
75
75
  const year = Number(matches[1])
@@ -82,6 +82,9 @@ export class LocalTime {
82
82
  date = d
83
83
  } else if (typeof d === 'number') {
84
84
  date = new Date(d * 1000)
85
+ } else if (typeof (d as any) !== 'string') {
86
+ // unexpected type, e.g Function or something
87
+ return null
85
88
  } else {
86
89
  date = new Date(d.slice(0, 19))
87
90
  }
@@ -182,7 +182,6 @@ export class Fetcher {
182
182
  signature,
183
183
  } as FetcherResponse<any>
184
184
 
185
- /* eslint-disable no-await-in-loop */
186
185
  while (!res.retryStatus.retryStopped) {
187
186
  const started = Date.now()
188
187
 
@@ -205,6 +204,8 @@ export class Fetcher {
205
204
  // For example, CORS error would result in "TypeError: failed to fetch" here
206
205
  res.err = err as Error
207
206
  res.ok = false
207
+ // important to set it to undefined, otherwise it can keep the previous value (from previous try)
208
+ res.fetchResponse = undefined
208
209
  }
209
210
  res.statusFamily = this.getStatusFamily(res)
210
211
 
@@ -128,7 +128,7 @@ export async function pRetry<T>(
128
128
  let delay = initialDelay
129
129
  let attempt = 0
130
130
 
131
- /* eslint-disable no-await-in-loop, no-constant-condition */
131
+ /* eslint-disable no-constant-condition */
132
132
  while (true) {
133
133
  const started = Date.now()
134
134
 
package/src/seq/seq.ts CHANGED
@@ -158,8 +158,6 @@ export function _seq<T>(initialValue: T | typeof END, nextFn: AbortableMapper<T,
158
158
  return Sequence.create(initialValue, nextFn)
159
159
  }
160
160
 
161
- /* eslint-disable no-await-in-loop */
162
-
163
161
  /**
164
162
  * Experimental.
165
163
  * Feasibility to be proven.