fch 5.1.0 → 5.1.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.
- package/index.d.ts +142 -0
- package/package.json +3 -2
package/index.d.ts
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
type Store = {
|
|
2
|
+
get: (key: string) => Promise<any>;
|
|
3
|
+
set: (key: string, value: any, options: { EX: number }) => Promise<null>;
|
|
4
|
+
del: (key: string) => Promise<null>;
|
|
5
|
+
keys: () => Promise<string[]>;
|
|
6
|
+
exists: (key: string) => Promise<boolean>;
|
|
7
|
+
flushAll: () => Promise<any>;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
type Cache =
|
|
11
|
+
| boolean
|
|
12
|
+
| number
|
|
13
|
+
| string
|
|
14
|
+
| {
|
|
15
|
+
expire?: number | string;
|
|
16
|
+
store?: Store;
|
|
17
|
+
shouldCache?: (request) => boolean;
|
|
18
|
+
createKey?: (request) => string;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
type Headers = { [name: string]: string };
|
|
22
|
+
type Query = { [name: string]: string };
|
|
23
|
+
|
|
24
|
+
type Methods = "get" | "head" | "post" | "patch" | "put" | "delete";
|
|
25
|
+
|
|
26
|
+
type Options = {
|
|
27
|
+
url?: string;
|
|
28
|
+
method?: Methods;
|
|
29
|
+
query?: Query;
|
|
30
|
+
headers?: Headers;
|
|
31
|
+
baseUrl?: string;
|
|
32
|
+
baseURL?: string;
|
|
33
|
+
cache?: Cache;
|
|
34
|
+
output?: string;
|
|
35
|
+
credentials?: string;
|
|
36
|
+
before?: (req: any) => any;
|
|
37
|
+
after?: (res: any) => any;
|
|
38
|
+
error?: (error: Error) => any;
|
|
39
|
+
signal?: AbortSignal;
|
|
40
|
+
[key: string]: any;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
type FullOptions = Options & { url: "string" };
|
|
44
|
+
|
|
45
|
+
type Body =
|
|
46
|
+
| string
|
|
47
|
+
| any[]
|
|
48
|
+
| { [key: string]: any }
|
|
49
|
+
| FormData
|
|
50
|
+
| HTMLFormElement
|
|
51
|
+
| SubmitEvent
|
|
52
|
+
| ReadableStream;
|
|
53
|
+
|
|
54
|
+
declare function fch(url: string, options?: Options): Promise<any>;
|
|
55
|
+
|
|
56
|
+
declare module fch {
|
|
57
|
+
var url: string;
|
|
58
|
+
var method: Methods;
|
|
59
|
+
var query: Query;
|
|
60
|
+
var headers: Headers;
|
|
61
|
+
var baseUrl: string;
|
|
62
|
+
var baseURL: string;
|
|
63
|
+
var cache: Cache;
|
|
64
|
+
var output: string;
|
|
65
|
+
var credentials: string;
|
|
66
|
+
var before: (req: any) => any;
|
|
67
|
+
var after: (res: any) => any;
|
|
68
|
+
var error: (error: Error) => any;
|
|
69
|
+
var signal: AbortSignal;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Creates an instance of fch with the given options, perfect for custom APIs:
|
|
73
|
+
*
|
|
74
|
+
* ```js
|
|
75
|
+
* const api = fch.create({
|
|
76
|
+
* baseUrl: 'https://api.myapi.com/',
|
|
77
|
+
* headers: { apiVersion: 2 }
|
|
78
|
+
* })
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
function create(options?: FullOptions): typeof fch;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Make a GET request to the given endpoint:
|
|
85
|
+
*
|
|
86
|
+
* ```js
|
|
87
|
+
* const data = await fch.get('/path')
|
|
88
|
+
* const data = await fch.get('/path', options)
|
|
89
|
+
*/
|
|
90
|
+
function get(url: string, options?: Options): Promise<any>;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Make a HEAD request to the given endpoint:
|
|
94
|
+
*
|
|
95
|
+
* ```js
|
|
96
|
+
* const data = await fch.head('/path')
|
|
97
|
+
* const data = await fch.head('/path', options)
|
|
98
|
+
*/
|
|
99
|
+
function head(url: string, options?: Options): Promise<any>;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Make a POST request to the given endpoint:
|
|
103
|
+
*
|
|
104
|
+
* ```js
|
|
105
|
+
* const data = await fch.post('/path', body)
|
|
106
|
+
* const data = await fch.post('/path', body, options)
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
function post(url: string, body?: Body, options?: Options): Promise<any>;
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Make a PATCH request to the given endpoint:
|
|
113
|
+
*
|
|
114
|
+
* ```js
|
|
115
|
+
* const data = await fch.patch('/path', body)
|
|
116
|
+
* const data = await fch.patch('/path', body, options)
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
function put(url: string, body?: Body, options?: Options): Promise<any>;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Make a PUT request to the given endpoint:
|
|
123
|
+
*
|
|
124
|
+
* ```js
|
|
125
|
+
* const data = await fch.put('/path', body)
|
|
126
|
+
* const data = await fch.put('/path', body, options)
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
function patch(url: string, body?: Body, options?: Options): Promise<any>;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Make a DELETE request to the given endpoint:
|
|
133
|
+
*
|
|
134
|
+
* ```js
|
|
135
|
+
* const data = await fch.del('/patd)
|
|
136
|
+
* const data = await fch.del('/patd, options)
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
function del(url: string, body?: Body, options?: Options): Promise<any>;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export default fch;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fch",
|
|
3
|
-
"version": "5.1.
|
|
3
|
+
"version": "5.1.1",
|
|
4
4
|
"description": "Fetch interface with better promises, deduplication, defaults, etc.",
|
|
5
5
|
"homepage": "https://github.com/franciscop/fetch",
|
|
6
6
|
"repository": "https://github.com/franciscop/fetch.git",
|
|
@@ -24,7 +24,8 @@
|
|
|
24
24
|
],
|
|
25
25
|
"main": "index.min.js",
|
|
26
26
|
"files": [
|
|
27
|
-
"index.min.js"
|
|
27
|
+
"index.min.js",
|
|
28
|
+
"index.d.ts"
|
|
28
29
|
],
|
|
29
30
|
"types": "index.d.ts",
|
|
30
31
|
"type": "module",
|