@alwatr/fetch 2.2.0 → 3.0.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/type.d.ts DELETED
@@ -1,90 +0,0 @@
1
- import type { Methods, QueryParameters, StringifyableRecord, UserAuth } from '@alwatr/type';
2
- export type CacheStrategy = 'network_only' | 'network_first' | 'cache_only' | 'cache_first' | 'update_cache' | 'stale_while_revalidate';
3
- export type CacheDuplicate = 'never' | 'always' | 'until_load' | 'auto';
4
- export interface FetchOptions extends RequestInit {
5
- /**
6
- * Request URL.
7
- */
8
- url: string;
9
- /**
10
- * A string to set request's method.
11
- *
12
- * @default 'GET'
13
- */
14
- method?: Methods;
15
- /**
16
- * A Headers object to set request's headers.
17
- */
18
- headers?: Record<string, string>;
19
- /**
20
- * A timeout for the fetch request.
21
- * Set `0` for disable it.
22
- *
23
- * Use with cation, you will have memory leak issue in nodejs.
24
- *
25
- * @default 10_000 ms
26
- */
27
- timeout?: number;
28
- /**
29
- * If fetch response not acceptable or timed out, it will retry the request.
30
- *
31
- * @default 3
32
- */
33
- retry?: number;
34
- /**
35
- * Delay before each retries.
36
- *
37
- * @default 1_000 ms
38
- */
39
- retryDelay?: number;
40
- /**
41
- * Simple memory caching for remove duplicate/parallel requests.
42
- *
43
- * - `never`: Never use memory caching.
44
- * - `always`: Always use memory caching and remove all duplicate requests.
45
- * - `until_load`: Cache parallel requests until request completed (it will be removed after the promise resolved).
46
- * - `auto`: If CacheStorage was supported use `until_load` strategy else use `always`.
47
- *
48
- * @default 'never'
49
- */
50
- removeDuplicate?: CacheDuplicate;
51
- /**
52
- * Strategies for caching.
53
- *
54
- * - `network_only`: Only network request without any cache.
55
- * - `network_first`: Network first, falling back to cache.
56
- * - `cache_only`: Cache only without any network request.
57
- * - `cache_first`: Cache first, falling back to network.
58
- * - `update_cache`: Like `network_only` but with update cache.
59
- * - `stale_while_revalidate`: Fastest strategy, Use cached first but always request network to update the cache.
60
- *
61
- * @default 'network_only'
62
- */
63
- cacheStrategy?: CacheStrategy;
64
- /**
65
- * Revalidate callback for `stale_while_revalidate` cache strategy.
66
- */
67
- revalidateCallback?: (response: Response) => void | Promise<void>;
68
- /**
69
- * Cache storage custom name.
70
- */
71
- cacheStorageName?: string;
72
- /**
73
- * Body as JS Object.
74
- */
75
- bodyJson?: StringifyableRecord;
76
- /**
77
- * URL Query Parameters as JS Object.
78
- */
79
- queryParameters?: QueryParameters;
80
- /**
81
- * Add token to Authentication bearer header.
82
- */
83
- token?: string;
84
- /**
85
- * Add user id and token to Authentication bearer header.
86
- */
87
- userAuth?: UserAuth;
88
- }
89
- export type StringifyableFetchOptions = Pick<FetchOptions, 'url' | 'bodyJson' | 'cache' | 'cacheStorageName' | 'cacheStrategy' | 'headers' | 'credentials' | 'keepalive' | 'method' | 'mode' | 'queryParameters' | 'removeDuplicate' | 'timeout' | 'token' | 'retry' | 'retryDelay' | 'referrer' | 'referrerPolicy' | 'userAuth'>;
90
- //# sourceMappingURL=type.d.ts.map
package/type.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["src/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,QAAQ,EAAC,MAAM,cAAc,CAAC;AAE1F,MAAM,MAAM,aAAa,GACrB,cAAc,GACd,eAAe,GACf,YAAY,GACZ,aAAa,GACb,cAAc,GACd,wBAAwB,CAAC;AAE7B,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,QAAQ,GAAG,YAAY,GAAG,MAAM,CAAC;AAExE,MAAM,WAAW,YAAa,SAAQ,WAAW;IAC/C;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IAEZ;;;;OAIG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEjC;;;;;;;OAOG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;;;;;;;OASG;IACH,eAAe,CAAC,EAAE,cAAc,CAAC;IAEjC;;;;;;;;;;;OAWG;IACH,aAAa,CAAC,EAAE,aAAa,CAAC;IAE9B;;OAEG;IACH,kBAAkB,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAElE;;OAEG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B;;OAEG;IACH,QAAQ,CAAC,EAAE,mBAAmB,CAAC;IAE/B;;OAEG;IACH,eAAe,CAAC,EAAE,eAAe,CAAC;IAElC;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED,MAAM,MAAM,yBAAyB,GAAG,IAAI,CAC1C,YAAY,EACV,KAAK,GACL,UAAU,GACV,OAAO,GACP,kBAAkB,GAClB,eAAe,GACf,SAAS,GACT,aAAa,GACb,WAAW,GACX,QAAQ,GACR,MAAM,GACN,iBAAiB,GACjB,iBAAiB,GACjB,SAAS,GACT,OAAO,GACP,OAAO,GACP,YAAY,GACZ,UAAU,GACV,gBAAgB,GAChB,UAAU,CACb,CAAC"}
package/type.js DELETED
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=type.js.map
package/type.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"type.js","sourceRoot":"","sources":["src/type.ts"],"names":[],"mappings":"","sourcesContent":["import type {Methods, QueryParameters, StringifyableRecord, UserAuth} from '@alwatr/type';\n\nexport type CacheStrategy =\n | 'network_only'\n | 'network_first'\n | 'cache_only'\n | 'cache_first'\n | 'update_cache'\n | 'stale_while_revalidate';\n\nexport type CacheDuplicate = 'never' | 'always' | 'until_load' | 'auto';\n\nexport interface FetchOptions extends RequestInit {\n /**\n * Request URL.\n */\n url: string;\n\n /**\n * A string to set request's method.\n *\n * @default 'GET'\n */\n method?: Methods;\n\n /**\n * A Headers object to set request's headers.\n */\n headers?: Record<string, string>;\n\n /**\n * A timeout for the fetch request.\n * Set `0` for disable it.\n *\n * Use with cation, you will have memory leak issue in nodejs.\n *\n * @default 10_000 ms\n */\n timeout?: number;\n\n /**\n * If fetch response not acceptable or timed out, it will retry the request.\n *\n * @default 3\n */\n retry?: number;\n\n /**\n * Delay before each retries.\n *\n * @default 1_000 ms\n */\n retryDelay?: number;\n\n /**\n * Simple memory caching for remove duplicate/parallel requests.\n *\n * - `never`: Never use memory caching.\n * - `always`: Always use memory caching and remove all duplicate requests.\n * - `until_load`: Cache parallel requests until request completed (it will be removed after the promise resolved).\n * - `auto`: If CacheStorage was supported use `until_load` strategy else use `always`.\n *\n * @default 'never'\n */\n removeDuplicate?: CacheDuplicate;\n\n /**\n * Strategies for caching.\n *\n * - `network_only`: Only network request without any cache.\n * - `network_first`: Network first, falling back to cache.\n * - `cache_only`: Cache only without any network request.\n * - `cache_first`: Cache first, falling back to network.\n * - `update_cache`: Like `network_only` but with update cache.\n * - `stale_while_revalidate`: Fastest strategy, Use cached first but always request network to update the cache.\n *\n * @default 'network_only'\n */\n cacheStrategy?: CacheStrategy;\n\n /**\n * Revalidate callback for `stale_while_revalidate` cache strategy.\n */\n revalidateCallback?: (response: Response) => void | Promise<void>;\n\n /**\n * Cache storage custom name.\n */\n cacheStorageName?: string;\n\n /**\n * Body as JS Object.\n */\n bodyJson?: StringifyableRecord;\n\n /**\n * URL Query Parameters as JS Object.\n */\n queryParameters?: QueryParameters;\n\n /**\n * Add token to Authentication bearer header.\n */\n token?: string;\n\n /**\n * Add user id and token to Authentication bearer header.\n */\n userAuth?: UserAuth;\n}\n\nexport type StringifyableFetchOptions = Pick<\n FetchOptions,\n | 'url'\n | 'bodyJson'\n | 'cache'\n | 'cacheStorageName'\n | 'cacheStrategy'\n | 'headers'\n | 'credentials'\n | 'keepalive'\n | 'method'\n | 'mode'\n | 'queryParameters'\n | 'removeDuplicate'\n | 'timeout'\n | 'token'\n | 'retry'\n | 'retryDelay'\n | 'referrer'\n | 'referrerPolicy'\n | 'userAuth'\n>;\n"]}