1 |
|
2 | import type { Buffer } from 'node:buffer';
|
3 | import type { Spread } from 'type-fest';
|
4 | import type { CancelableRequest } from './as-promise/types.js';
|
5 | import type { Response } from './core/response.js';
|
6 | import type Options from './core/options.js';
|
7 | import { type PaginationOptions, type OptionsInit } from './core/options.js';
|
8 | import type Request from './core/index.js';
|
9 | type Except<ObjectType, KeysType extends keyof ObjectType> = Pick<ObjectType, Exclude<keyof ObjectType, KeysType>>;
|
10 | type Merge<FirstType, SecondType> = Except<FirstType, Extract<keyof FirstType, keyof SecondType>> & SecondType;
|
11 |
|
12 |
|
13 |
|
14 | export type InstanceDefaults = {
|
15 | |
16 |
|
17 |
|
18 | options: Options;
|
19 | |
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | handlers: HandlerFunction[];
|
27 | |
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | mutableDefaults: boolean;
|
34 | };
|
35 |
|
36 |
|
37 |
|
38 | export type GotReturn = Request | CancelableRequest;
|
39 |
|
40 |
|
41 |
|
42 |
|
43 | export type HandlerFunction = <T extends GotReturn>(options: Options, next: (options: Options) => T) => T | Promise<T>;
|
44 |
|
45 |
|
46 |
|
47 | export type ExtendOptions = {
|
48 | |
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 | handlers?: HandlerFunction[];
|
56 | |
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 | mutableDefaults?: boolean;
|
63 | } & OptionsInit;
|
64 | export type StrictOptions = Except<OptionsInit, 'isStream' | 'responseType' | 'resolveBodyOnly'>;
|
65 | export type StreamOptions = Merge<OptionsInit, {
|
66 | isStream?: true;
|
67 | }>;
|
68 | export type OptionsWithPagination<T = unknown, R = unknown> = Merge<OptionsInit, {
|
69 | pagination?: PaginationOptions<T, R>;
|
70 | }>;
|
71 |
|
72 |
|
73 |
|
74 | export type GotPaginate = {
|
75 | |
76 |
|
77 |
|
78 | <T, R = unknown>(url: string | URL, options?: OptionsWithPagination<T, R>): AsyncIterableIterator<T>;
|
79 | |
80 |
|
81 |
|
82 | <T, R = unknown>(options?: OptionsWithPagination<T, R>): AsyncIterableIterator<T>;
|
83 | |
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 | each: (<T, R = unknown>(url: string | URL, options?: OptionsWithPagination<T, R>) => AsyncIterableIterator<T>) & (<T, R = unknown>(options?: OptionsWithPagination<T, R>) => AsyncIterableIterator<T>);
|
106 | /**
|
107 | Returns a Promise for an array of all results.
|
108 |
|
109 | See pagination.options for more pagination options.
|
110 |
|
111 | @example
|
112 | ```
|
113 | import got from 'got';
|
114 |
|
115 | const countLimit = 10;
|
116 |
|
117 | const results = await got.paginate.all('https:
|
118 | pagination: {countLimit}
|
119 | });
|
120 |
|
121 | console.log(`Printing latest ${countLimit} Got commits (newest to oldest):`);
|
122 | console.log(results);
|
123 | ```
|
124 | */
|
125 | all: (<T, R = unknown>(url: string | URL, options?: OptionsWithPagination<T, R>) => Promise<T[]>) & (<T, R = unknown>(options?: OptionsWithPagination<T, R>) => Promise<T[]>);
|
126 | };
|
127 | export type OptionsOfTextResponseBody = Merge<StrictOptions, {
|
128 | isStream?: false;
|
129 | responseType?: 'text';
|
130 | }>;
|
131 | export type OptionsOfTextResponseBodyOnly = Merge<StrictOptions, {
|
132 | isStream?: false;
|
133 | resolveBodyOnly: true;
|
134 | responseType?: 'text';
|
135 | }>;
|
136 | export type OptionsOfTextResponseBodyWrapped = Merge<StrictOptions, {
|
137 | isStream?: false;
|
138 | resolveBodyOnly: false;
|
139 | responseType?: 'text';
|
140 | }>;
|
141 | export type OptionsOfJSONResponseBody = Merge<StrictOptions, {
|
142 | isStream?: false;
|
143 | responseType?: 'json';
|
144 | }>;
|
145 | export type OptionsOfJSONResponseBodyOnly = Merge<StrictOptions, {
|
146 | isStream?: false;
|
147 | resolveBodyOnly: true;
|
148 | responseType?: 'json';
|
149 | }>;
|
150 | export type OptionsOfJSONResponseBodyWrapped = Merge<StrictOptions, {
|
151 | isStream?: false;
|
152 | resolveBodyOnly: false;
|
153 | responseType?: 'json';
|
154 | }>;
|
155 | export type OptionsOfBufferResponseBody = Merge<StrictOptions, {
|
156 | isStream?: false;
|
157 | responseType?: 'buffer';
|
158 | }>;
|
159 | export type OptionsOfBufferResponseBodyOnly = Merge<StrictOptions, {
|
160 | isStream?: false;
|
161 | resolveBodyOnly: true;
|
162 | responseType?: 'buffer';
|
163 | }>;
|
164 | export type OptionsOfBufferResponseBodyWrapped = Merge<StrictOptions, {
|
165 | isStream?: false;
|
166 | resolveBodyOnly: false;
|
167 | responseType?: 'buffer';
|
168 | }>;
|
169 | export type OptionsOfUnknownResponseBody = Merge<StrictOptions, {
|
170 | isStream?: false;
|
171 | }>;
|
172 | export type OptionsOfUnknownResponseBodyOnly = Merge<StrictOptions, {
|
173 | isStream?: false;
|
174 | resolveBodyOnly: true;
|
175 | }>;
|
176 | export type OptionsOfUnknownResponseBodyWrapped = Merge<StrictOptions, {
|
177 | isStream?: false;
|
178 | resolveBodyOnly: false;
|
179 | }>;
|
180 | export type GotRequestFunction<U extends ExtendOptions = Record<string, unknown>> = {
|
181 | (url: string | URL, options?: OptionsOfTextResponseBody): U['resolveBodyOnly'] extends true ? CancelableRequest<string> : CancelableRequest<Response<string>>;
|
182 | <T>(url: string | URL, options?: OptionsOfJSONResponseBody): U['resolveBodyOnly'] extends true ? CancelableRequest<T> : CancelableRequest<Response<T>>;
|
183 | (url: string | URL, options?: OptionsOfBufferResponseBody): U['resolveBodyOnly'] extends true ? CancelableRequest<Buffer> : CancelableRequest<Response<Buffer>>;
|
184 | (url: string | URL, options?: OptionsOfUnknownResponseBody): U['resolveBodyOnly'] extends true ? CancelableRequest : CancelableRequest<Response>;
|
185 | (url: string | URL, options?: OptionsOfTextResponseBodyWrapped): CancelableRequest<Response<string>>;
|
186 | <T>(url: string | URL, options?: OptionsOfJSONResponseBodyWrapped): CancelableRequest<Response<T>>;
|
187 | (url: string | URL, options?: OptionsOfBufferResponseBodyWrapped): CancelableRequest<Response<Buffer>>;
|
188 | (url: string | URL, options?: OptionsOfUnknownResponseBodyWrapped): CancelableRequest<Response>;
|
189 | (url: string | URL, options?: OptionsOfTextResponseBodyOnly): CancelableRequest<string>;
|
190 | <T>(url: string | URL, options?: OptionsOfJSONResponseBodyOnly): CancelableRequest<T>;
|
191 | (url: string | URL, options?: OptionsOfBufferResponseBodyOnly): CancelableRequest<Buffer>;
|
192 | (url: string | URL, options?: OptionsOfUnknownResponseBodyOnly): CancelableRequest;
|
193 | (options: OptionsOfTextResponseBody): U['resolveBodyOnly'] extends true ? CancelableRequest<string> : CancelableRequest<Response<string>>;
|
194 | <T>(options: OptionsOfJSONResponseBody): U['resolveBodyOnly'] extends true ? CancelableRequest<T> : CancelableRequest<Response<T>>;
|
195 | (options: OptionsOfBufferResponseBody): U['resolveBodyOnly'] extends true ? CancelableRequest<Buffer> : CancelableRequest<Response<Buffer>>;
|
196 | (options: OptionsOfUnknownResponseBody): U['resolveBodyOnly'] extends true ? CancelableRequest : CancelableRequest<Response>;
|
197 | (options: OptionsOfTextResponseBodyWrapped): CancelableRequest<Response<string>>;
|
198 | <T>(options: OptionsOfJSONResponseBodyWrapped): CancelableRequest<Response<T>>;
|
199 | (options: OptionsOfBufferResponseBodyWrapped): CancelableRequest<Response<Buffer>>;
|
200 | (options: OptionsOfUnknownResponseBodyWrapped): CancelableRequest<Response>;
|
201 | (options: OptionsOfTextResponseBodyOnly): CancelableRequest<string>;
|
202 | <T>(options: OptionsOfJSONResponseBodyOnly): CancelableRequest<T>;
|
203 | (options: OptionsOfBufferResponseBodyOnly): CancelableRequest<Buffer>;
|
204 | (options: OptionsOfUnknownResponseBodyOnly): CancelableRequest;
|
205 | (url: string | URL, options?: Merge<OptionsInit, {
|
206 | isStream: true;
|
207 | }>): Request;
|
208 | (options: Merge<OptionsInit, {
|
209 | isStream: true;
|
210 | }>): Request;
|
211 | (url: string | URL, options?: OptionsInit): CancelableRequest | Request;
|
212 | (options: OptionsInit): CancelableRequest | Request;
|
213 | (url: undefined, options: undefined, defaults: Options): CancelableRequest | Request;
|
214 | };
|
215 | /**
|
216 | All available HTTP request methods provided by Got.
|
217 | */
|
218 | export type HTTPAlias = 'get' | 'post' | 'put' | 'patch' | 'head' | 'delete';
|
219 | type GotStreamFunction = ((url?: string | URL, options?: Merge<OptionsInit, {
|
220 | isStream?: true;
|
221 | }>) => Request) & ((options?: Merge<OptionsInit, {
|
222 | isStream?: true;
|
223 | }>) => Request);
|
224 | /**
|
225 | An instance of `got.stream()`.
|
226 | */
|
227 | export type GotStream = GotStreamFunction & Record<HTTPAlias, GotStreamFunction>;
|
228 | /**
|
229 | An instance of `got`.
|
230 | */
|
231 | export type Got<GotOptions extends ExtendOptions = ExtendOptions> = {
|
232 | /**
|
233 | Sets `options.isStream` to `true`.
|
234 |
|
235 | Returns a [duplex stream](https:
|
236 | - request
|
237 | - response
|
238 | - redirect
|
239 | - uploadProgress
|
240 | - downloadProgress
|
241 | - error
|
242 | */
|
243 | stream: GotStream;
|
244 | |
245 |
|
246 |
|
247 |
|
248 |
|
249 |
|
250 |
|
251 |
|
252 |
|
253 |
|
254 |
|
255 |
|
256 |
|
257 |
|
258 |
|
259 |
|
260 |
|
261 |
|
262 |
|
263 |
|
264 |
|
265 |
|
266 | paginate: GotPaginate;
|
267 | |
268 |
|
269 |
|
270 | defaults: InstanceDefaults;
|
271 | |
272 |
|
273 |
|
274 |
|
275 |
|
276 |
|
277 |
|
278 |
|
279 |
|
280 |
|
281 |
|
282 |
|
283 |
|
284 |
|
285 |
|
286 |
|
287 |
|
288 |
|
289 |
|
290 |
|
291 |
|
292 |
|
293 |
|
294 |
|
295 |
|
296 |
|
297 |
|
298 |
|
299 |
|
300 |
|
301 | extend<T extends Array<Got | ExtendOptions>>(...instancesOrOptions: T): Got<MergeExtendsConfig<T>>;
|
302 | } & Record<HTTPAlias, GotRequestFunction<GotOptions>> & GotRequestFunction<GotOptions>;
|
303 | export type ExtractExtendOptions<T> = T extends Got<infer GotOptions> ? GotOptions : T;
|
304 |
|
305 |
|
306 |
|
307 | export type MergeExtendsConfig<Value extends Array<Got | ExtendOptions>> = Value extends readonly [Value[0], ...infer NextValue] ? NextValue[0] extends undefined ? Value[0] extends infer OnlyValue ? OnlyValue extends ExtendOptions ? OnlyValue : OnlyValue extends Got<infer GotOptions> ? GotOptions : OnlyValue : never : ExtractExtendOptions<Value[0]> extends infer FirstArg extends ExtendOptions ? ExtractExtendOptions<NextValue[0] extends ExtendOptions | Got ? NextValue[0] : never> extends infer NextArg extends ExtendOptions ? Spread<FirstArg, NextArg> extends infer Merged extends ExtendOptions ? NextValue extends [NextValue[0], ...infer NextRest] ? NextRest extends Array<Got | ExtendOptions> ? MergeExtendsConfig<[Merged, ...NextRest]> : never : never : never : never : never : never;
|
308 | export {};
|
309 |
|
\ | No newline at end of file |