Skip to content

Commit 36fbc5b

Browse files
authored
fix: retry as client parameter (#163)
since microlink supports configurable retry behavior, it's necessary to distinct between client and server side.
1 parent 8bf2dac commit 36fbc5b

File tree

7 files changed

+11
-64
lines changed

7 files changed

+11
-64
lines changed

lightweight/index.umd.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@
801801

802802
const getApiUrl = (
803803
url,
804-
{ data, apiKey, endpoint, retry, cache, ...opts } = {},
804+
{ data, apiKey, endpoint, ...opts } = {},
805805
{ responseType = 'json', headers: gotHeaders, ...gotOpts } = {}
806806
) => {
807807
const isPro = !!apiKey
@@ -820,7 +820,7 @@
820820
if (opts.stream) {
821821
responseType = streamResponseType
822822
}
823-
return [apiUrl, { ...gotOpts, responseType, cache, retry, headers }]
823+
return [apiUrl, { ...gotOpts, responseType, headers }]
824824
}
825825

826826
const createMql = defaultOpts => async (url, opts, gotOpts) => {
@@ -896,7 +896,7 @@
896896
MicrolinkError,
897897
got,
898898
flatten,
899-
VERSION: '0.13.11'
899+
VERSION: '0.13.20'
900900
})
901901

902902
lightweight$1.exports = mql

src/factory.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ const factory = streamResponseType => ({
9898

9999
const getApiUrl = (
100100
url,
101-
{ data, apiKey, endpoint, retry, cache, ...opts } = {},
101+
{ data, apiKey, endpoint, ...opts } = {},
102102
{ responseType = 'json', headers: gotHeaders, ...gotOpts } = {}
103103
) => {
104104
const isPro = !!apiKey
@@ -117,7 +117,7 @@ const factory = streamResponseType => ({
117117
if (opts.stream) {
118118
responseType = streamResponseType
119119
}
120-
return [apiUrl, { ...gotOpts, responseType, cache, retry, headers }]
120+
return [apiUrl, { ...gotOpts, responseType, headers }]
121121
}
122122

123123
const createMql = defaultOpts => async (url, opts, gotOpts) => {

test/error/client.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ clients.forEach(({ constructor: mql, target }) => {
2828
}
2929

3030
const error = await t.throwsAsync(
31-
mql('https://example.com', { endpoint: 'https://notexist.dev', retry: 3 }, { hooks }),
31+
mql('https://example.com', { endpoint: 'https://notexist.dev' }, { retry: 2, hooks }),
3232
{ instanceOf: mql.MicrolinkError }
3333
)
3434

35-
t.is(count, 3)
35+
t.is(count, 2)
3636
t.true(error.url === 'https://notexist.dev?url=https%3A%2F%2Fexample.com')
3737
t.true(error.code === 'EFATALCLIENT')
3838
t.true(error.status === 'error')

test/error/server.mjs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,8 @@ clients.forEach(({ constructor: mql, target }) => {
5555
mql('https://kikobeats.com', {
5656
timeout: 50,
5757
force: true,
58-
screenshot: true,
59-
retry: 0
60-
}),
58+
screenshot: true
59+
}, { retry: 0 }),
6160
{ instanceOf: mql.MicrolinkError }
6261
)
6362

test/opts.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ clients.forEach(({ constructor: mql, target }) => {
4141
test('node » cache support', async t => {
4242
const cache = new Map()
4343
let data
44-
data = await mql('https://kikobeats.com?ref=mql', { cache })
44+
data = await mql('https://kikobeats.com?ref=mql', {}, { cache })
4545
t.is(data.response.isFromCache, false)
46-
data = await mql('https://kikobeats.com?ref=mql', { cache })
46+
data = await mql('https://kikobeats.com?ref=mql', {}, { cache })
4747
t.is(data.response.isFromCache, true)
4848
})
4949
}

test/snapshots/get-api-url.mjs.md

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@ Generated by [AVA](https://avajs.dev).
1111
[
1212
'https://api.microlink.io/?url=https%3A%2F%2Fkikobeats.com',
1313
{
14-
cache: undefined,
1514
headers: {},
1615
responseType: 'json',
17-
retry: undefined,
1816
},
1917
]
2018

@@ -25,12 +23,10 @@ Generated by [AVA](https://avajs.dev).
2523
[
2624
'https://pro.microlink.io/?url=https%3A%2F%2Fkikobeats.com',
2725
{
28-
cache: undefined,
2926
headers: {
3027
'x-api-key': 'foobar',
3128
},
3229
responseType: 'json',
33-
retry: undefined,
3430
},
3531
]
3632

@@ -41,10 +37,8 @@ Generated by [AVA](https://avajs.dev).
4137
[
4238
'https://api.microlink.io/?url=https%3A%2F%2Fkikobeats.com&overlay.browser=dark',
4339
{
44-
cache: undefined,
4540
headers: {},
4641
responseType: 'json',
47-
retry: undefined,
4842
},
4943
]
5044

@@ -55,10 +49,8 @@ Generated by [AVA](https://avajs.dev).
5549
[
5650
'https://api.microlink.io/?url=https%3A%2F%2Fkikobeats.com',
5751
{
58-
cache: undefined,
5952
headers: {},
6053
responseType: 'json',
61-
retry: undefined,
6254
},
6355
]
6456

@@ -67,10 +59,8 @@ Generated by [AVA](https://avajs.dev).
6759
[
6860
'https://api.microlink.io/?url=https%3A%2F%2Fkikobeats.com',
6961
{
70-
cache: undefined,
7162
headers: {},
7263
responseType: 'json',
73-
retry: undefined,
7464
},
7565
]
7666

@@ -81,10 +71,8 @@ Generated by [AVA](https://avajs.dev).
8171
[
8272
'https://api.microlink.io/?url=https%3A%2F%2Fkikobeats.com',
8373
{
84-
cache: undefined,
8574
headers: {},
8675
responseType: 'json',
87-
retry: undefined,
8876
},
8977
]
9078

@@ -93,10 +81,8 @@ Generated by [AVA](https://avajs.dev).
9381
[
9482
'https://api.microlink.io/?url=https%3A%2F%2Fkikobeats.com',
9583
{
96-
cache: undefined,
9784
headers: {},
9885
responseType: 'json',
99-
retry: undefined,
10086
},
10187
]
10288

@@ -107,10 +93,8 @@ Generated by [AVA](https://avajs.dev).
10793
[
10894
'https://api.microlink.io/?url=https%3A%2F%2Fkikobeats.com&timeout=15000',
10995
{
110-
cache: undefined,
11196
headers: {},
11297
responseType: 'json',
113-
retry: undefined,
11498
},
11599
]
116100

@@ -119,10 +103,8 @@ Generated by [AVA](https://avajs.dev).
119103
[
120104
'https://api.microlink.io/?url=https%3A%2F%2Fkikobeats.com&timeout=28000',
121105
{
122-
cache: undefined,
123106
headers: {},
124107
responseType: 'json',
125-
retry: undefined,
126108
},
127109
]
128110

@@ -133,10 +115,8 @@ Generated by [AVA](https://avajs.dev).
133115
[
134116
'https://api.microlink.io/?url=https%3A%2F%2Fkikobeats.com&waitUntil=load',
135117
{
136-
cache: undefined,
137118
headers: {},
138119
responseType: 'json',
139-
retry: undefined,
140120
},
141121
]
142122

@@ -145,10 +125,8 @@ Generated by [AVA](https://avajs.dev).
145125
[
146126
'https://api.microlink.io/?url=https%3A%2F%2Fkikobeats.com&waitUntil.0=load&waitUntil.1=networkidle0',
147127
{
148-
cache: undefined,
149128
headers: {},
150129
responseType: 'json',
151-
retry: undefined,
152130
},
153131
]
154132

@@ -159,10 +137,8 @@ Generated by [AVA](https://avajs.dev).
159137
[
160138
'https://api.microlink.io/?url=https%3A%2F%2Fkikobeats.com',
161139
{
162-
cache: undefined,
163140
headers: {},
164141
responseType: 'json',
165-
retry: undefined,
166142
},
167143
]
168144

@@ -171,10 +147,8 @@ Generated by [AVA](https://avajs.dev).
171147
[
172148
'https://api.microlink.io/?url=https%3A%2F%2Fkikobeats.com&screenshot.element=%23screenshot',
173149
{
174-
cache: undefined,
175150
headers: {},
176151
responseType: 'json',
177-
retry: undefined,
178152
},
179153
]
180154

@@ -185,10 +159,8 @@ Generated by [AVA](https://avajs.dev).
185159
[
186160
'https://api.microlink.io/?url=https%3A%2F%2Fkikobeats.com',
187161
{
188-
cache: undefined,
189162
headers: {},
190163
responseType: 'json',
191-
retry: undefined,
192164
},
193165
]
194166

@@ -199,12 +171,10 @@ Generated by [AVA](https://avajs.dev).
199171
[
200172
'https://pro.microlink.io/?url=https%3A%2F%2Fkikobeats.com',
201173
{
202-
cache: undefined,
203174
headers: {
204175
'x-api-key': 'foobar',
205176
},
206177
responseType: 'json',
207-
retry: undefined,
208178
},
209179
]
210180

@@ -215,10 +185,8 @@ Generated by [AVA](https://avajs.dev).
215185
[
216186
'https://api.microlink.io/?url=https%3A%2F%2Fkikobeats.com&overlay.browser=dark',
217187
{
218-
cache: undefined,
219188
headers: {},
220189
responseType: 'json',
221-
retry: undefined,
222190
},
223191
]
224192

@@ -229,10 +197,8 @@ Generated by [AVA](https://avajs.dev).
229197
[
230198
'https://api.microlink.io/?url=https%3A%2F%2Fkikobeats.com',
231199
{
232-
cache: undefined,
233200
headers: {},
234201
responseType: 'json',
235-
retry: undefined,
236202
},
237203
]
238204

@@ -241,10 +207,8 @@ Generated by [AVA](https://avajs.dev).
241207
[
242208
'https://api.microlink.io/?url=https%3A%2F%2Fkikobeats.com',
243209
{
244-
cache: undefined,
245210
headers: {},
246211
responseType: 'json',
247-
retry: undefined,
248212
},
249213
]
250214

@@ -255,10 +219,8 @@ Generated by [AVA](https://avajs.dev).
255219
[
256220
'https://api.microlink.io/?url=https%3A%2F%2Fkikobeats.com',
257221
{
258-
cache: undefined,
259222
headers: {},
260223
responseType: 'json',
261-
retry: undefined,
262224
},
263225
]
264226

@@ -267,10 +229,8 @@ Generated by [AVA](https://avajs.dev).
267229
[
268230
'https://api.microlink.io/?url=https%3A%2F%2Fkikobeats.com',
269231
{
270-
cache: undefined,
271232
headers: {},
272233
responseType: 'json',
273-
retry: undefined,
274234
},
275235
]
276236

@@ -281,10 +241,8 @@ Generated by [AVA](https://avajs.dev).
281241
[
282242
'https://api.microlink.io/?url=https%3A%2F%2Fkikobeats.com&timeout=15000',
283243
{
284-
cache: undefined,
285244
headers: {},
286245
responseType: 'json',
287-
retry: undefined,
288246
},
289247
]
290248

@@ -293,10 +251,8 @@ Generated by [AVA](https://avajs.dev).
293251
[
294252
'https://api.microlink.io/?url=https%3A%2F%2Fkikobeats.com&timeout=28000',
295253
{
296-
cache: undefined,
297254
headers: {},
298255
responseType: 'json',
299-
retry: undefined,
300256
},
301257
]
302258

@@ -307,10 +263,8 @@ Generated by [AVA](https://avajs.dev).
307263
[
308264
'https://api.microlink.io/?url=https%3A%2F%2Fkikobeats.com&waitUntil=load',
309265
{
310-
cache: undefined,
311266
headers: {},
312267
responseType: 'json',
313-
retry: undefined,
314268
},
315269
]
316270

@@ -319,10 +273,8 @@ Generated by [AVA](https://avajs.dev).
319273
[
320274
'https://api.microlink.io/?url=https%3A%2F%2Fkikobeats.com&waitUntil.0=load&waitUntil.1=networkidle0',
321275
{
322-
cache: undefined,
323276
headers: {},
324277
responseType: 'json',
325-
retry: undefined,
326278
},
327279
]
328280

@@ -333,10 +285,8 @@ Generated by [AVA](https://avajs.dev).
333285
[
334286
'https://api.microlink.io/?url=https%3A%2F%2Fkikobeats.com',
335287
{
336-
cache: undefined,
337288
headers: {},
338289
responseType: 'json',
339-
retry: undefined,
340290
},
341291
]
342292

@@ -345,9 +295,7 @@ Generated by [AVA](https://avajs.dev).
345295
[
346296
'https://api.microlink.io/?url=https%3A%2F%2Fkikobeats.com&screenshot.element=%23screenshot',
347297
{
348-
cache: undefined,
349298
headers: {},
350299
responseType: 'json',
351-
retry: undefined,
352300
},
353301
]

test/snapshots/get-api-url.mjs.snap

-64 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)