@naturalcycles/js-lib 15.52.0 → 15.54.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/dist/http/fetcher.d.ts +1 -0
- package/dist/http/fetcher.js +13 -2
- package/dist/http/fetcher.model.d.ts +2 -1
- package/dist/typeFest.d.ts +14 -0
- package/package.json +1 -1
- package/src/http/fetcher.model.ts +2 -1
- package/src/http/fetcher.ts +14 -2
- package/src/typeFest.ts +15 -0
package/dist/http/fetcher.d.ts
CHANGED
package/dist/http/fetcher.js
CHANGED
|
@@ -591,7 +591,7 @@ export class Fetcher {
|
|
|
591
591
|
}
|
|
592
592
|
const norm = _merge({
|
|
593
593
|
baseUrl: '',
|
|
594
|
-
name:
|
|
594
|
+
name: this.getFetcherName(cfg),
|
|
595
595
|
inputUrl: '',
|
|
596
596
|
responseType: 'json',
|
|
597
597
|
searchParams: {},
|
|
@@ -622,10 +622,21 @@ export class Fetcher {
|
|
|
622
622
|
hooks: {},
|
|
623
623
|
throwHttpErrors: true,
|
|
624
624
|
errorData: {},
|
|
625
|
-
}, _omit(cfg, ['method', 'credentials', 'headers', 'redirect', 'logger']));
|
|
625
|
+
}, _omit(cfg, ['method', 'credentials', 'headers', 'redirect', 'logger', 'name']));
|
|
626
626
|
norm.init.headers = _mapKeys(norm.init.headers, k => k.toLowerCase());
|
|
627
627
|
return norm;
|
|
628
628
|
}
|
|
629
|
+
getFetcherName(cfg) {
|
|
630
|
+
let { name } = cfg;
|
|
631
|
+
if (!name && cfg.baseUrl) {
|
|
632
|
+
// derive FetcherName from baseUrl
|
|
633
|
+
const url = URL.parse(cfg.baseUrl);
|
|
634
|
+
if (url) {
|
|
635
|
+
name = url.hostname;
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
return name;
|
|
639
|
+
}
|
|
629
640
|
normalizeOptions(opt) {
|
|
630
641
|
const req = {
|
|
631
642
|
..._pick(this.cfg, [
|
|
@@ -5,9 +5,10 @@ import type { ErrorData } from '../error/error.model.js';
|
|
|
5
5
|
import type { CommonLogger } from '../log/commonLogger.js';
|
|
6
6
|
import type { AnyObject, NumberOfMilliseconds, Promisable, Reviver, UnixTimestampMillis } from '../types.js';
|
|
7
7
|
import type { HttpMethod, HttpStatusFamily } from './http.model.js';
|
|
8
|
-
export interface FetcherNormalizedCfg extends Required<Omit<FetcherCfg, 'dispatcher'>>, Omit<FetcherRequest, 'started' | 'fullUrl' | 'logRequest' | 'logRequestBody' | 'logResponse' | 'logResponseBody' | 'debug' | 'redirect' | 'credentials' | 'throwHttpErrors' | 'errorData'> {
|
|
8
|
+
export interface FetcherNormalizedCfg extends Required<Omit<FetcherCfg, 'dispatcher' | 'name'>>, Omit<FetcherRequest, 'started' | 'fullUrl' | 'logRequest' | 'logRequestBody' | 'logResponse' | 'logResponseBody' | 'debug' | 'redirect' | 'credentials' | 'throwHttpErrors' | 'errorData'> {
|
|
9
9
|
logger: CommonLogger;
|
|
10
10
|
searchParams: Record<string, any>;
|
|
11
|
+
name?: string;
|
|
11
12
|
}
|
|
12
13
|
export type FetcherBeforeRequestHook = (req: FetcherRequest) => Promisable<void>;
|
|
13
14
|
export type FetcherAfterResponseHook = <BODY = unknown>(res: FetcherResponse<BODY>) => Promisable<void>;
|
package/dist/typeFest.d.ts
CHANGED
|
@@ -167,6 +167,20 @@ export type ConditionalExcept<Base, Condition> = Except<Base, ConditionalKeys<Ba
|
|
|
167
167
|
```
|
|
168
168
|
*/
|
|
169
169
|
export type ConditionalPick<Base, Condition> = Pick<Base, ConditionalKeys<Base, Condition>>;
|
|
170
|
+
/**
|
|
171
|
+
Makes one property of T required instead of optional.
|
|
172
|
+
@example
|
|
173
|
+
```
|
|
174
|
+
import {RequireProp} from 'type-fest';
|
|
175
|
+
interface Example {
|
|
176
|
+
a?: string
|
|
177
|
+
b?: string
|
|
178
|
+
};
|
|
179
|
+
type ExampleA = RequireProp<Example, 'a'>;
|
|
180
|
+
//=> {a: string; b?: string};
|
|
181
|
+
```
|
|
182
|
+
*/
|
|
183
|
+
export type RequireProp<T, K extends keyof T> = Required<Pick<T, K>> & T;
|
|
170
184
|
/**
|
|
171
185
|
Matches any [typed array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray), like `Uint8Array` or `Float64Array`.
|
|
172
186
|
*/
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@ import type { HttpMethod, HttpStatusFamily } from './http.model.js'
|
|
|
15
15
|
|
|
16
16
|
export interface FetcherNormalizedCfg
|
|
17
17
|
extends
|
|
18
|
-
Required<Omit<FetcherCfg, 'dispatcher'>>,
|
|
18
|
+
Required<Omit<FetcherCfg, 'dispatcher' | 'name'>>,
|
|
19
19
|
Omit<
|
|
20
20
|
FetcherRequest,
|
|
21
21
|
| 'started'
|
|
@@ -32,6 +32,7 @@ export interface FetcherNormalizedCfg
|
|
|
32
32
|
> {
|
|
33
33
|
logger: CommonLogger
|
|
34
34
|
searchParams: Record<string, any>
|
|
35
|
+
name?: string
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
export type FetcherBeforeRequestHook = (req: FetcherRequest) => Promisable<void>
|
package/src/http/fetcher.ts
CHANGED
|
@@ -726,7 +726,7 @@ export class Fetcher {
|
|
|
726
726
|
const norm: FetcherNormalizedCfg = _merge(
|
|
727
727
|
{
|
|
728
728
|
baseUrl: '',
|
|
729
|
-
name:
|
|
729
|
+
name: this.getFetcherName(cfg),
|
|
730
730
|
inputUrl: '',
|
|
731
731
|
responseType: 'json',
|
|
732
732
|
searchParams: {},
|
|
@@ -758,7 +758,7 @@ export class Fetcher {
|
|
|
758
758
|
throwHttpErrors: true,
|
|
759
759
|
errorData: {},
|
|
760
760
|
},
|
|
761
|
-
_omit(cfg, ['method', 'credentials', 'headers', 'redirect', 'logger']),
|
|
761
|
+
_omit(cfg, ['method', 'credentials', 'headers', 'redirect', 'logger', 'name']),
|
|
762
762
|
)
|
|
763
763
|
|
|
764
764
|
norm.init.headers = _mapKeys(norm.init.headers, k => k.toLowerCase())
|
|
@@ -766,6 +766,18 @@ export class Fetcher {
|
|
|
766
766
|
return norm
|
|
767
767
|
}
|
|
768
768
|
|
|
769
|
+
private getFetcherName(cfg: FetcherCfg): string | undefined {
|
|
770
|
+
let { name } = cfg
|
|
771
|
+
if (!name && cfg.baseUrl) {
|
|
772
|
+
// derive FetcherName from baseUrl
|
|
773
|
+
const url = URL.parse(cfg.baseUrl)
|
|
774
|
+
if (url) {
|
|
775
|
+
name = url.hostname
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
return name
|
|
779
|
+
}
|
|
780
|
+
|
|
769
781
|
private normalizeOptions(opt: FetcherOptions): FetcherRequest {
|
|
770
782
|
const req: FetcherRequest = {
|
|
771
783
|
..._pick(this.cfg, [
|
package/src/typeFest.ts
CHANGED
|
@@ -197,6 +197,21 @@ export type ConditionalExcept<Base, Condition> = Except<Base, ConditionalKeys<Ba
|
|
|
197
197
|
*/
|
|
198
198
|
export type ConditionalPick<Base, Condition> = Pick<Base, ConditionalKeys<Base, Condition>>
|
|
199
199
|
|
|
200
|
+
/**
|
|
201
|
+
Makes one property of T required instead of optional.
|
|
202
|
+
@example
|
|
203
|
+
```
|
|
204
|
+
import {RequireProp} from 'type-fest';
|
|
205
|
+
interface Example {
|
|
206
|
+
a?: string
|
|
207
|
+
b?: string
|
|
208
|
+
};
|
|
209
|
+
type ExampleA = RequireProp<Example, 'a'>;
|
|
210
|
+
//=> {a: string; b?: string};
|
|
211
|
+
```
|
|
212
|
+
*/
|
|
213
|
+
export type RequireProp<T, K extends keyof T> = Required<Pick<T, K>> & T
|
|
214
|
+
|
|
200
215
|
/**
|
|
201
216
|
Matches any [typed array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray), like `Uint8Array` or `Float64Array`.
|
|
202
217
|
*/
|