@slango/ristretto 1.0.52 → 1.0.53
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/package.json +8 -5
- package/CHANGELOG.md +0 -394
- package/eslint.config.js +0 -1
- package/lint-staged.config.js +0 -1
- package/src/abortable/index.ts +0 -50
- package/src/index.ts +0 -35
- package/src/middleware/index.ts +0 -20
- package/src/middleware/runner.spec.ts +0 -174
- package/src/middleware/runner.ts +0 -65
- package/src/utils/HttpError.ts +0 -9
- package/src/utils/abortableRequest.spec.ts +0 -50
- package/src/utils/abortableRequest.ts +0 -22
- package/src/utils/auth.spec.ts +0 -58
- package/src/utils/auth.ts +0 -16
- package/src/utils/baseUrl.ts +0 -17
- package/src/utils/body.spec.ts +0 -123
- package/src/utils/body.ts +0 -74
- package/src/utils/httpMethod.ts +0 -11
- package/src/utils/queryParams.spec.ts +0 -75
- package/src/utils/queryParams.ts +0 -31
- package/src/utils/request.spec.ts +0 -180
- package/src/utils/request.ts +0 -57
- package/src/utils/status.spec.ts +0 -66
- package/src/utils/status.ts +0 -15
- package/src/utils/withBaseUrl.spec.ts +0 -53
- package/src/utils/withBaseUrl.ts +0 -12
- package/tsconfig.build.json +0 -10
- package/tsconfig.json +0 -10
- package/vitest.config.js +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@slango/ristretto",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.53",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Opinionated rest client",
|
|
6
6
|
"repository": {
|
|
@@ -9,6 +9,9 @@
|
|
|
9
9
|
"directory": "packages/ristretto"
|
|
10
10
|
},
|
|
11
11
|
"type": "module",
|
|
12
|
+
"files": [
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
12
15
|
"main": "./dist/index.js",
|
|
13
16
|
"types": "./dist/index.d.ts",
|
|
14
17
|
"exports": {
|
|
@@ -22,7 +25,7 @@
|
|
|
22
25
|
}
|
|
23
26
|
},
|
|
24
27
|
"dependencies": {
|
|
25
|
-
"@slango/tessera": "1.0.
|
|
28
|
+
"@slango/tessera": "1.0.30"
|
|
26
29
|
},
|
|
27
30
|
"devDependencies": {
|
|
28
31
|
"@types/node": "26.1.1",
|
|
@@ -32,9 +35,9 @@
|
|
|
32
35
|
"type-fest": "5.8.0",
|
|
33
36
|
"typescript": "6.0.3",
|
|
34
37
|
"vitest": "4.1.10",
|
|
35
|
-
"@slango.configs/eslint": "1.2.
|
|
36
|
-
"@slango.configs/
|
|
37
|
-
"@slango.configs/
|
|
38
|
+
"@slango.configs/eslint": "1.2.33",
|
|
39
|
+
"@slango.configs/typescript": "2.0.10",
|
|
40
|
+
"@slango.configs/vitest": "2.0.42"
|
|
38
41
|
},
|
|
39
42
|
"scripts": {
|
|
40
43
|
"build": "tsc -p tsconfig.build.json",
|
package/CHANGELOG.md
DELETED
|
@@ -1,394 +0,0 @@
|
|
|
1
|
-
# @slango/ristretto
|
|
2
|
-
|
|
3
|
-
## 1.0.52
|
|
4
|
-
|
|
5
|
-
### Patch Changes
|
|
6
|
-
|
|
7
|
-
- 7d321c6: Dependencies bump
|
|
8
|
-
- Updated dependencies [7d321c6]
|
|
9
|
-
- @slango/tessera@1.0.29
|
|
10
|
-
|
|
11
|
-
## 1.0.51
|
|
12
|
-
|
|
13
|
-
### Patch Changes
|
|
14
|
-
|
|
15
|
-
- 83f12c6: Dependencies bump
|
|
16
|
-
- @slango/tessera@1.0.28
|
|
17
|
-
|
|
18
|
-
## 1.0.50
|
|
19
|
-
|
|
20
|
-
### Patch Changes
|
|
21
|
-
|
|
22
|
-
- 463d9ce: Dependencies bump
|
|
23
|
-
- Updated dependencies [463d9ce]
|
|
24
|
-
- @slango/tessera@1.0.28
|
|
25
|
-
|
|
26
|
-
## 1.0.49
|
|
27
|
-
|
|
28
|
-
### Patch Changes
|
|
29
|
-
|
|
30
|
-
- 6d64ea9: Dependencies bump
|
|
31
|
-
|
|
32
|
-
## 1.0.48
|
|
33
|
-
|
|
34
|
-
### Patch Changes
|
|
35
|
-
|
|
36
|
-
- 02b8cd1: Dependencies bump
|
|
37
|
-
- Updated dependencies [02b8cd1]
|
|
38
|
-
- @slango/tessera@1.0.27
|
|
39
|
-
|
|
40
|
-
## 1.0.47
|
|
41
|
-
|
|
42
|
-
### Patch Changes
|
|
43
|
-
|
|
44
|
-
- f59dae8: Dependencies bump
|
|
45
|
-
- @slango/tessera@1.0.26
|
|
46
|
-
|
|
47
|
-
## 1.0.46
|
|
48
|
-
|
|
49
|
-
### Patch Changes
|
|
50
|
-
|
|
51
|
-
- 75b71f7: Dependencies bump
|
|
52
|
-
- Updated dependencies [75b71f7]
|
|
53
|
-
- @slango/tessera@1.0.26
|
|
54
|
-
|
|
55
|
-
## 1.0.45
|
|
56
|
-
|
|
57
|
-
### Patch Changes
|
|
58
|
-
|
|
59
|
-
- 7b9def8: Dependencies bump
|
|
60
|
-
- Updated dependencies [7b9def8]
|
|
61
|
-
- @slango/tessera@1.0.25
|
|
62
|
-
|
|
63
|
-
## 1.0.44
|
|
64
|
-
|
|
65
|
-
### Patch Changes
|
|
66
|
-
|
|
67
|
-
- dfd3015: Dependencies bump
|
|
68
|
-
- @slango/tessera@1.0.24
|
|
69
|
-
|
|
70
|
-
## 1.0.43
|
|
71
|
-
|
|
72
|
-
### Patch Changes
|
|
73
|
-
|
|
74
|
-
- 1052e1d: Dependencies bump
|
|
75
|
-
|
|
76
|
-
## 1.0.42
|
|
77
|
-
|
|
78
|
-
### Patch Changes
|
|
79
|
-
|
|
80
|
-
- 59effbe: Dependencies bump
|
|
81
|
-
- Updated dependencies [59effbe]
|
|
82
|
-
- @slango/tessera@1.0.24
|
|
83
|
-
|
|
84
|
-
## 1.0.41
|
|
85
|
-
|
|
86
|
-
### Patch Changes
|
|
87
|
-
|
|
88
|
-
- 3e79aa6: Dependencies bump
|
|
89
|
-
- Updated dependencies [3e79aa6]
|
|
90
|
-
- @slango/tessera@1.0.23
|
|
91
|
-
|
|
92
|
-
## 1.0.40
|
|
93
|
-
|
|
94
|
-
### Patch Changes
|
|
95
|
-
|
|
96
|
-
- 70230d2: Dependencies bump
|
|
97
|
-
- Updated dependencies [70230d2]
|
|
98
|
-
- @slango/tessera@1.0.22
|
|
99
|
-
|
|
100
|
-
## 1.0.39
|
|
101
|
-
|
|
102
|
-
### Patch Changes
|
|
103
|
-
|
|
104
|
-
- f4e8645: Dependencies bump
|
|
105
|
-
- Updated dependencies [f4e8645]
|
|
106
|
-
- @slango/tessera@1.0.21
|
|
107
|
-
|
|
108
|
-
## 1.0.38
|
|
109
|
-
|
|
110
|
-
### Patch Changes
|
|
111
|
-
|
|
112
|
-
- e80d5ac: Dependencies bump
|
|
113
|
-
- Updated dependencies [e80d5ac]
|
|
114
|
-
- @slango/tessera@1.0.20
|
|
115
|
-
|
|
116
|
-
## 1.0.37
|
|
117
|
-
|
|
118
|
-
### Patch Changes
|
|
119
|
-
|
|
120
|
-
- a692cf9: Dependencies bump
|
|
121
|
-
- Updated dependencies [a692cf9]
|
|
122
|
-
- @slango/tessera@1.0.19
|
|
123
|
-
|
|
124
|
-
## 1.0.36
|
|
125
|
-
|
|
126
|
-
### Patch Changes
|
|
127
|
-
|
|
128
|
-
- dca0a26: Dependencies bump
|
|
129
|
-
- Updated dependencies [dca0a26]
|
|
130
|
-
- @slango/tessera@1.0.18
|
|
131
|
-
|
|
132
|
-
## 1.0.35
|
|
133
|
-
|
|
134
|
-
### Patch Changes
|
|
135
|
-
|
|
136
|
-
- df2e3c2: Dependencies bump
|
|
137
|
-
- Updated dependencies [df2e3c2]
|
|
138
|
-
- @slango/tessera@1.0.17
|
|
139
|
-
|
|
140
|
-
## 1.0.34
|
|
141
|
-
|
|
142
|
-
### Patch Changes
|
|
143
|
-
|
|
144
|
-
- 6ab8613: Dependencies bump
|
|
145
|
-
- Updated dependencies [6ab8613]
|
|
146
|
-
- @slango/tessera@1.0.16
|
|
147
|
-
|
|
148
|
-
## 1.0.33
|
|
149
|
-
|
|
150
|
-
### Patch Changes
|
|
151
|
-
|
|
152
|
-
- 07ec4aa: Dependencies bump
|
|
153
|
-
- Updated dependencies [07ec4aa]
|
|
154
|
-
- @slango/tessera@1.0.15
|
|
155
|
-
|
|
156
|
-
## 1.0.32
|
|
157
|
-
|
|
158
|
-
### Patch Changes
|
|
159
|
-
|
|
160
|
-
- 57f6c46: Dependencies bump
|
|
161
|
-
- Updated dependencies [57f6c46]
|
|
162
|
-
- @slango/tessera@1.0.14
|
|
163
|
-
|
|
164
|
-
## 1.0.31
|
|
165
|
-
|
|
166
|
-
### Patch Changes
|
|
167
|
-
|
|
168
|
-
- 4ba0ccb: Dependencies bump
|
|
169
|
-
- Updated dependencies [4ba0ccb]
|
|
170
|
-
- @slango/tessera@1.0.13
|
|
171
|
-
|
|
172
|
-
## 1.0.30
|
|
173
|
-
|
|
174
|
-
### Patch Changes
|
|
175
|
-
|
|
176
|
-
- 09ac7a7: Dependencies bump
|
|
177
|
-
- Updated dependencies [09ac7a7]
|
|
178
|
-
- @slango/tessera@1.0.12
|
|
179
|
-
|
|
180
|
-
## 1.0.29
|
|
181
|
-
|
|
182
|
-
### Patch Changes
|
|
183
|
-
|
|
184
|
-
- ad32208: Dependencies bump
|
|
185
|
-
- Updated dependencies [ad32208]
|
|
186
|
-
- @slango/tessera@1.0.11
|
|
187
|
-
|
|
188
|
-
## 1.0.28
|
|
189
|
-
|
|
190
|
-
### Patch Changes
|
|
191
|
-
|
|
192
|
-
- 35aaf02: Dependencies bump
|
|
193
|
-
- @slango/tessera@1.0.10
|
|
194
|
-
|
|
195
|
-
## 1.0.27
|
|
196
|
-
|
|
197
|
-
### Patch Changes
|
|
198
|
-
|
|
199
|
-
- fafa8e1: Dependencies bump
|
|
200
|
-
- Updated dependencies [fafa8e1]
|
|
201
|
-
- @slango/tessera@1.0.10
|
|
202
|
-
|
|
203
|
-
## 1.0.26
|
|
204
|
-
|
|
205
|
-
### Patch Changes
|
|
206
|
-
|
|
207
|
-
- ec2131e: Dependencies bump
|
|
208
|
-
- @slango/tessera@1.0.9
|
|
209
|
-
|
|
210
|
-
## 1.0.25
|
|
211
|
-
|
|
212
|
-
### Patch Changes
|
|
213
|
-
|
|
214
|
-
- ebe4053: Dependencies bump
|
|
215
|
-
- @slango/tessera@1.0.9
|
|
216
|
-
|
|
217
|
-
## 1.0.24
|
|
218
|
-
|
|
219
|
-
### Patch Changes
|
|
220
|
-
|
|
221
|
-
- 4010cfc: Dependencies bump
|
|
222
|
-
- @slango/tessera@1.0.9
|
|
223
|
-
|
|
224
|
-
## 1.0.23
|
|
225
|
-
|
|
226
|
-
### Patch Changes
|
|
227
|
-
|
|
228
|
-
- 8ee771f: Dependencies bump
|
|
229
|
-
- @slango/tessera@1.0.9
|
|
230
|
-
|
|
231
|
-
## 1.0.22
|
|
232
|
-
|
|
233
|
-
### Patch Changes
|
|
234
|
-
|
|
235
|
-
- 1731369: Dependencies bump
|
|
236
|
-
- @slango/tessera@1.0.9
|
|
237
|
-
|
|
238
|
-
## 1.0.21
|
|
239
|
-
|
|
240
|
-
### Patch Changes
|
|
241
|
-
|
|
242
|
-
- 3ceebbb: Dependencies bump
|
|
243
|
-
- Updated dependencies [3ceebbb]
|
|
244
|
-
- @slango/tessera@1.0.9
|
|
245
|
-
|
|
246
|
-
## 1.0.20
|
|
247
|
-
|
|
248
|
-
### Patch Changes
|
|
249
|
-
|
|
250
|
-
- 2ab1c4d: Dependencies bump
|
|
251
|
-
- @slango/tessera@1.0.8
|
|
252
|
-
|
|
253
|
-
## 1.0.19
|
|
254
|
-
|
|
255
|
-
### Patch Changes
|
|
256
|
-
|
|
257
|
-
- 9f290cf: Dependencies bump
|
|
258
|
-
- @slango/tessera@1.0.8
|
|
259
|
-
|
|
260
|
-
## 1.0.18
|
|
261
|
-
|
|
262
|
-
### Patch Changes
|
|
263
|
-
|
|
264
|
-
- 4e2e552: Dependencies bump
|
|
265
|
-
- Updated dependencies [4e2e552]
|
|
266
|
-
- @slango/tessera@1.0.8
|
|
267
|
-
|
|
268
|
-
## 1.0.17
|
|
269
|
-
|
|
270
|
-
### Patch Changes
|
|
271
|
-
|
|
272
|
-
- b6cdd05: Dependencies bump
|
|
273
|
-
- Updated dependencies [b6cdd05]
|
|
274
|
-
- @slango/tessera@1.0.7
|
|
275
|
-
|
|
276
|
-
## 1.0.16
|
|
277
|
-
|
|
278
|
-
### Patch Changes
|
|
279
|
-
|
|
280
|
-
- 7ceb0df: Dependencies bump
|
|
281
|
-
- @slango/tessera@1.0.6
|
|
282
|
-
|
|
283
|
-
## 1.0.15
|
|
284
|
-
|
|
285
|
-
### Patch Changes
|
|
286
|
-
|
|
287
|
-
- 86530f1: Dependencies bump
|
|
288
|
-
- Updated dependencies [86530f1]
|
|
289
|
-
- @slango/tessera@1.0.6
|
|
290
|
-
|
|
291
|
-
## 1.0.14
|
|
292
|
-
|
|
293
|
-
### Patch Changes
|
|
294
|
-
|
|
295
|
-
- 8519268: Dependencies bump
|
|
296
|
-
- Updated dependencies [8519268]
|
|
297
|
-
- @slango/tessera@1.0.5
|
|
298
|
-
|
|
299
|
-
## 1.0.13
|
|
300
|
-
|
|
301
|
-
### Patch Changes
|
|
302
|
-
|
|
303
|
-
- 5bcda82: Dependencies bump
|
|
304
|
-
- Updated dependencies [5bcda82]
|
|
305
|
-
- @slango/tessera@1.0.4
|
|
306
|
-
|
|
307
|
-
## 1.0.12
|
|
308
|
-
|
|
309
|
-
### Patch Changes
|
|
310
|
-
|
|
311
|
-
- cc43aa2: Dependencies bump
|
|
312
|
-
- @slango/tessera@1.0.3
|
|
313
|
-
|
|
314
|
-
## 1.0.11
|
|
315
|
-
|
|
316
|
-
### Patch Changes
|
|
317
|
-
|
|
318
|
-
- a661329: Dependencies bump
|
|
319
|
-
|
|
320
|
-
## 1.0.10
|
|
321
|
-
|
|
322
|
-
### Patch Changes
|
|
323
|
-
|
|
324
|
-
- 72ffa91: Dependnecies bump and eslint presets normalization
|
|
325
|
-
- @slango/tessera@1.0.3
|
|
326
|
-
|
|
327
|
-
## 1.0.9
|
|
328
|
-
|
|
329
|
-
### Patch Changes
|
|
330
|
-
|
|
331
|
-
- fb024e5: Dependencies bump
|
|
332
|
-
- Updated dependencies [fb024e5]
|
|
333
|
-
- @slango/tessera@1.0.3
|
|
334
|
-
|
|
335
|
-
## 1.0.8
|
|
336
|
-
|
|
337
|
-
### Patch Changes
|
|
338
|
-
|
|
339
|
-
- 7d6305d: Dependencies bump
|
|
340
|
-
- Updated dependencies [7d6305d]
|
|
341
|
-
- @slango/tessera@1.0.2
|
|
342
|
-
|
|
343
|
-
## 1.0.7
|
|
344
|
-
|
|
345
|
-
### Patch Changes
|
|
346
|
-
|
|
347
|
-
- 60f7e37: Dependencies bump
|
|
348
|
-
- @slango/tessera@1.0.1
|
|
349
|
-
|
|
350
|
-
## 1.0.6
|
|
351
|
-
|
|
352
|
-
### Patch Changes
|
|
353
|
-
|
|
354
|
-
- 87e2b79: Dependencies bump
|
|
355
|
-
- Updated dependencies [87e2b79]
|
|
356
|
-
- @slango/tessera@1.0.1
|
|
357
|
-
|
|
358
|
-
## 1.0.5
|
|
359
|
-
|
|
360
|
-
### Patch Changes
|
|
361
|
-
|
|
362
|
-
- 7912c01: Dependencies bump
|
|
363
|
-
|
|
364
|
-
## 1.0.4
|
|
365
|
-
|
|
366
|
-
### Patch Changes
|
|
367
|
-
|
|
368
|
-
- 0f0e49c: Dependencies bump
|
|
369
|
-
|
|
370
|
-
## 1.0.3
|
|
371
|
-
|
|
372
|
-
### Patch Changes
|
|
373
|
-
|
|
374
|
-
- c73ab09: Dependencies bump
|
|
375
|
-
- @slango/tessera@1.0.0
|
|
376
|
-
|
|
377
|
-
## 1.0.2
|
|
378
|
-
|
|
379
|
-
### Patch Changes
|
|
380
|
-
|
|
381
|
-
- 4016ce6: withBaseUrl helper
|
|
382
|
-
|
|
383
|
-
## 1.0.1
|
|
384
|
-
|
|
385
|
-
### Patch Changes
|
|
386
|
-
|
|
387
|
-
- Updated dependencies [9d73d40]
|
|
388
|
-
- @slango/tessera@1.0.0
|
|
389
|
-
|
|
390
|
-
## 1.0.0
|
|
391
|
-
|
|
392
|
-
### Major Changes
|
|
393
|
-
|
|
394
|
-
- 759bc27: First version (renamed from @slango/rest-client)
|
package/eslint.config.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from '@slango.configs/eslint/typescript-isomorphic.js';
|
package/lint-staged.config.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from '@slango.configs/lint-staged/typescript.js';
|
package/src/abortable/index.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { AbortablePromise, abortableRequest } from '../utils/abortableRequest.js';
|
|
2
|
-
import { HttpMethod } from '../utils/httpMethod.js';
|
|
3
|
-
import { Request as BaseRequest, RequestOptionsWithoutUrl, RequestURL } from '../utils/request.js';
|
|
4
|
-
|
|
5
|
-
export type { AbortablePromise } from '../utils/abortableRequest.js';
|
|
6
|
-
export { withBearerToken } from '../utils/auth.js';
|
|
7
|
-
export type { BaseURL } from '../utils/baseUrl.js';
|
|
8
|
-
export { withBaseUrl } from '../utils/baseUrl.js';
|
|
9
|
-
|
|
10
|
-
export { withFormDataBody, withJsonBody } from '../utils/body.js';
|
|
11
|
-
export { HttpError } from '../utils/HttpError.js';
|
|
12
|
-
export { withQueryParams } from '../utils/queryParams.js';
|
|
13
|
-
export type { RequestOptionsWithoutUrl, RequestURL } from '../utils/request.js';
|
|
14
|
-
export { withNotFoundAsNull } from '../utils/status.js';
|
|
15
|
-
|
|
16
|
-
export type Request<Response> = BaseRequest<Response, AbortablePromise<Response>>;
|
|
17
|
-
|
|
18
|
-
const abortableRequestFactory =
|
|
19
|
-
(method: HttpMethod) =>
|
|
20
|
-
<Response>(url: RequestURL) =>
|
|
21
|
-
(options?: RequestOptionsWithoutUrl): AbortablePromise<Response> =>
|
|
22
|
-
abortableRequest<Response>(method, { ...options, url });
|
|
23
|
-
|
|
24
|
-
export const get = abortableRequestFactory(HttpMethod.GET);
|
|
25
|
-
|
|
26
|
-
export const del = abortableRequestFactory(HttpMethod.DELETE);
|
|
27
|
-
|
|
28
|
-
export const post = abortableRequestFactory(HttpMethod.POST);
|
|
29
|
-
|
|
30
|
-
export const put = abortableRequestFactory(HttpMethod.PUT);
|
|
31
|
-
|
|
32
|
-
export const patch = abortableRequestFactory(HttpMethod.PATCH);
|
|
33
|
-
|
|
34
|
-
export const withTransformer =
|
|
35
|
-
<Input, Output>(transformFn: (input: Input) => Output) =>
|
|
36
|
-
(req: Request<Input>): Request<Output> =>
|
|
37
|
-
(options?: RequestOptionsWithoutUrl) => {
|
|
38
|
-
const abortablePromise = req(options);
|
|
39
|
-
|
|
40
|
-
const wrappedPromise = abortablePromise.then((result: Input) =>
|
|
41
|
-
transformFn ? transformFn(result) : result,
|
|
42
|
-
) as AbortablePromise<Output>;
|
|
43
|
-
|
|
44
|
-
if ('abort' in abortablePromise) {
|
|
45
|
-
// Assign the abort function if it's an AbortablePromise
|
|
46
|
-
wrappedPromise.abort = abortablePromise.abort;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return wrappedPromise;
|
|
50
|
-
};
|
package/src/index.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { HttpMethod } from './utils/httpMethod.js';
|
|
2
|
-
import {
|
|
3
|
-
Request as BaseRequest,
|
|
4
|
-
request,
|
|
5
|
-
RequestOptionsWithoutUrl,
|
|
6
|
-
RequestURL,
|
|
7
|
-
} from './utils/request.js';
|
|
8
|
-
|
|
9
|
-
export { withBearerToken } from './utils/auth.js';
|
|
10
|
-
export type { BaseURL } from './utils/baseUrl.js';
|
|
11
|
-
export { withBaseUrl } from './utils/baseUrl.js';
|
|
12
|
-
export { withFormDataBody, withJsonBody } from './utils/body.js';
|
|
13
|
-
export { HttpError } from './utils/HttpError.js';
|
|
14
|
-
export { withQueryParams } from './utils/queryParams.js';
|
|
15
|
-
export type { RequestOptionsWithoutUrl, RequestURL } from './utils/request.js';
|
|
16
|
-
|
|
17
|
-
export { withNotFoundAsNull } from './utils/status.js';
|
|
18
|
-
|
|
19
|
-
export type Request<Response> = BaseRequest<Response, Promise<Response>>;
|
|
20
|
-
|
|
21
|
-
const requestFactory =
|
|
22
|
-
(method: HttpMethod) =>
|
|
23
|
-
<Response>(url: RequestURL): Request<Response> =>
|
|
24
|
-
(options?: RequestOptionsWithoutUrl): Promise<Response> =>
|
|
25
|
-
request<Response>(method, { ...options, url });
|
|
26
|
-
|
|
27
|
-
export const get = requestFactory(HttpMethod.GET);
|
|
28
|
-
|
|
29
|
-
export const del = requestFactory(HttpMethod.DELETE);
|
|
30
|
-
|
|
31
|
-
export const post = requestFactory(HttpMethod.POST);
|
|
32
|
-
|
|
33
|
-
export const put = requestFactory(HttpMethod.PUT);
|
|
34
|
-
|
|
35
|
-
export const patch = requestFactory(HttpMethod.PATCH);
|
package/src/middleware/index.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Promisable } from 'type-fest';
|
|
2
|
-
|
|
3
|
-
import { RequestOptions } from '../utils/request.js';
|
|
4
|
-
|
|
5
|
-
export type PreRequestMiddlewareContext = {
|
|
6
|
-
request: RequestOptions;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export type PostResponseMiddlewareContext = PreRequestMiddlewareContext & {
|
|
10
|
-
response: Response;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export type MiddlewareNext = (error?: Error) => Promisable<void>;
|
|
14
|
-
|
|
15
|
-
export type Middleware<Context> = (ctx: Context, next: MiddlewareNext) => Promisable<void>;
|
|
16
|
-
|
|
17
|
-
export {
|
|
18
|
-
addPostResponseMiddleware as usePostResponse,
|
|
19
|
-
addPreRequestMiddleware as usePreRequest,
|
|
20
|
-
} from './runner.js';
|
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
MiddlewareNext,
|
|
5
|
-
PostResponseMiddlewareContext,
|
|
6
|
-
PreRequestMiddlewareContext,
|
|
7
|
-
} from './index.js';
|
|
8
|
-
import {
|
|
9
|
-
addPostResponseMiddleware,
|
|
10
|
-
addPreRequestMiddleware,
|
|
11
|
-
clearPostResponseMiddlewares,
|
|
12
|
-
clearPreRequestMiddlewares,
|
|
13
|
-
removePostResponseMiddleware,
|
|
14
|
-
removePreRequestMiddleware,
|
|
15
|
-
runPostResponse,
|
|
16
|
-
runPreRequest,
|
|
17
|
-
} from './runner.js';
|
|
18
|
-
|
|
19
|
-
const createPreRequestContext = (): PreRequestMiddlewareContext => ({
|
|
20
|
-
request: { url: 'https://example.com', method: 'GET', headers: {} },
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
const createPostResponseContext = (): PostResponseMiddlewareContext => ({
|
|
24
|
-
request: { url: 'https://example.com', method: 'GET', headers: {} },
|
|
25
|
-
response: new Response(null, { status: 200 }),
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
describe('runner.ts', () => {
|
|
29
|
-
beforeEach(() => {
|
|
30
|
-
clearPostResponseMiddlewares();
|
|
31
|
-
clearPreRequestMiddlewares();
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('should add and remove pre-request middleware', async () => {
|
|
35
|
-
const middleware1 = vi.fn((ctx, next: MiddlewareNext) => next());
|
|
36
|
-
const middleware2 = vi.fn();
|
|
37
|
-
|
|
38
|
-
addPreRequestMiddleware(middleware1);
|
|
39
|
-
addPreRequestMiddleware(middleware2);
|
|
40
|
-
await runPreRequest(createPreRequestContext());
|
|
41
|
-
expect(middleware1).toHaveBeenCalledTimes(1);
|
|
42
|
-
expect(middleware2).toHaveBeenCalledTimes(1);
|
|
43
|
-
|
|
44
|
-
removePreRequestMiddleware(middleware2);
|
|
45
|
-
await runPreRequest(createPreRequestContext());
|
|
46
|
-
expect(middleware1).toHaveBeenCalledTimes(2);
|
|
47
|
-
expect(middleware2).toHaveBeenCalledTimes(1);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('should add and remove post-request middleware', async () => {
|
|
51
|
-
const middleware1 = vi.fn((ctx, next: MiddlewareNext) => next());
|
|
52
|
-
const middleware2 = vi.fn();
|
|
53
|
-
|
|
54
|
-
addPostResponseMiddleware(middleware1);
|
|
55
|
-
addPostResponseMiddleware(middleware2);
|
|
56
|
-
await runPostResponse(createPostResponseContext());
|
|
57
|
-
expect(middleware1).toHaveBeenCalledTimes(1);
|
|
58
|
-
expect(middleware2).toHaveBeenCalledTimes(1);
|
|
59
|
-
|
|
60
|
-
removePostResponseMiddleware(middleware2);
|
|
61
|
-
await runPostResponse(createPostResponseContext());
|
|
62
|
-
expect(middleware1).toHaveBeenCalledTimes(2);
|
|
63
|
-
expect(middleware2).toHaveBeenCalledTimes(1);
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it('should run pre-request middlewares in order and modify context', async () => {
|
|
67
|
-
const middleware1 = vi.fn(async (ctx: PreRequestMiddlewareContext, next: MiddlewareNext) => {
|
|
68
|
-
(ctx.request.headers! as Record<string, string>)['X-Test'] = 'Middleware1';
|
|
69
|
-
(ctx.request.headers! as Record<string, string>)['X-Override'] = 'Middleware1';
|
|
70
|
-
await next();
|
|
71
|
-
});
|
|
72
|
-
const middleware2 = vi.fn(async (ctx: PreRequestMiddlewareContext, next: MiddlewareNext) => {
|
|
73
|
-
(ctx.request.headers! as Record<string, string>)['X-Chain'] = 'Middleware2';
|
|
74
|
-
(ctx.request.headers! as Record<string, string>)['X-Override'] = 'Middleware2';
|
|
75
|
-
await next();
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
addPreRequestMiddleware(middleware1);
|
|
79
|
-
addPreRequestMiddleware(middleware2);
|
|
80
|
-
|
|
81
|
-
const context = createPreRequestContext();
|
|
82
|
-
await runPreRequest(context);
|
|
83
|
-
|
|
84
|
-
expect(middleware1).toHaveBeenCalledOnce();
|
|
85
|
-
expect(middleware2).toHaveBeenCalledOnce();
|
|
86
|
-
expect(context.request.headers).toEqual({
|
|
87
|
-
'X-Test': 'Middleware1',
|
|
88
|
-
'X-Chain': 'Middleware2',
|
|
89
|
-
'X-Override': 'Middleware2',
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it('should run post-response middlewares in order and modify context', async () => {
|
|
94
|
-
const middleware1 = vi.fn(async (ctx: PostResponseMiddlewareContext, next: MiddlewareNext) => {
|
|
95
|
-
ctx.response.headers.set('X-Test', 'Middleware1');
|
|
96
|
-
ctx.response.headers.set('X-Override', 'Middleware1');
|
|
97
|
-
await next();
|
|
98
|
-
});
|
|
99
|
-
const middleware2 = vi.fn(async (ctx: PostResponseMiddlewareContext, next: MiddlewareNext) => {
|
|
100
|
-
ctx.response.headers.set('X-Chain', 'Middleware2');
|
|
101
|
-
ctx.response.headers.set('X-Override', 'Middleware2');
|
|
102
|
-
|
|
103
|
-
await next();
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
addPostResponseMiddleware(middleware1);
|
|
107
|
-
addPostResponseMiddleware(middleware2);
|
|
108
|
-
|
|
109
|
-
const context = createPostResponseContext();
|
|
110
|
-
await runPostResponse(context);
|
|
111
|
-
|
|
112
|
-
expect(middleware1).toHaveBeenCalledOnce();
|
|
113
|
-
expect(middleware2).toHaveBeenCalledOnce();
|
|
114
|
-
expect(context.response.headers.get('X-Test')).toBe('Middleware1');
|
|
115
|
-
expect(context.response.headers.get('X-Chain')).toBe('Middleware2');
|
|
116
|
-
expect(context.response.headers.get('X-Override')).toBe('Middleware2');
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it('should handle errors in pre-request middlewares and stop pipeline', async () => {
|
|
120
|
-
const middleware1 = vi.fn(async (ctx: PreRequestMiddlewareContext, next: MiddlewareNext) => {
|
|
121
|
-
await next();
|
|
122
|
-
});
|
|
123
|
-
const errorMiddleware = vi.fn(() => {
|
|
124
|
-
throw new Error('Test error');
|
|
125
|
-
});
|
|
126
|
-
const middleware2 = vi.fn(async (ctx: PreRequestMiddlewareContext, next: MiddlewareNext) => {
|
|
127
|
-
await next();
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
addPreRequestMiddleware(middleware1);
|
|
131
|
-
addPreRequestMiddleware(errorMiddleware);
|
|
132
|
-
addPreRequestMiddleware(middleware2);
|
|
133
|
-
|
|
134
|
-
const context = createPreRequestContext();
|
|
135
|
-
|
|
136
|
-
await expect(runPreRequest(context)).rejects.toThrow('Test error');
|
|
137
|
-
|
|
138
|
-
expect(middleware1).toHaveBeenCalledOnce();
|
|
139
|
-
expect(errorMiddleware).toHaveBeenCalledOnce();
|
|
140
|
-
expect(middleware2).not.toHaveBeenCalled();
|
|
141
|
-
|
|
142
|
-
removePreRequestMiddleware(middleware1);
|
|
143
|
-
removePreRequestMiddleware(errorMiddleware);
|
|
144
|
-
removePreRequestMiddleware(middleware2);
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
it('should handle errors in post-response middlewares and stop pipeline', async () => {
|
|
148
|
-
const middleware1 = vi.fn(async (ctx: PostResponseMiddlewareContext, next: MiddlewareNext) => {
|
|
149
|
-
await next();
|
|
150
|
-
});
|
|
151
|
-
const errorMiddleware = vi.fn(() => {
|
|
152
|
-
throw new Error('Test error');
|
|
153
|
-
});
|
|
154
|
-
const middleware2 = vi.fn(async (ctx: PostResponseMiddlewareContext, next: MiddlewareNext) => {
|
|
155
|
-
await next();
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
addPostResponseMiddleware(middleware1);
|
|
159
|
-
addPostResponseMiddleware(errorMiddleware);
|
|
160
|
-
addPostResponseMiddleware(middleware2);
|
|
161
|
-
|
|
162
|
-
const context = createPostResponseContext();
|
|
163
|
-
|
|
164
|
-
await expect(runPostResponse(context)).rejects.toThrow('Test error');
|
|
165
|
-
|
|
166
|
-
expect(middleware1).toHaveBeenCalledOnce();
|
|
167
|
-
expect(errorMiddleware).toHaveBeenCalledOnce();
|
|
168
|
-
expect(middleware2).not.toHaveBeenCalled();
|
|
169
|
-
|
|
170
|
-
removePostResponseMiddleware(middleware1);
|
|
171
|
-
removePostResponseMiddleware(errorMiddleware);
|
|
172
|
-
removePostResponseMiddleware(middleware2);
|
|
173
|
-
});
|
|
174
|
-
});
|