lissa 1.0.3 → 1.0.5

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/README.md CHANGED
@@ -478,8 +478,9 @@ Decide if the occurred error should trigger a retry.
478
478
  The given errorType helps preselecting error types. Return false to not
479
479
  trigger a retry. Return nothing if the given errorType is correct. Return
480
480
  a string to redefine the errorType or use a custom one. The number of
481
- maximum retries can be configured as `on${errorType}`. Return "CustomError"
482
- and define the retries as { onCustomError: 3 }
481
+ maximum retries can be configured as `on${errorType}` or `@${errorType}`.
482
+ Return "CustomError" and define the retries as { onCustomError: 3 } or
483
+ as { '@CustomError': 3 }.
483
484
 
484
485
  ```js
485
486
  Lissa.retry({
package/lib/index.d.ts CHANGED
@@ -6,14 +6,21 @@ import { RequestInit, HeadersInit, BodyInit, Headers } from 'undici-types';
6
6
 
7
7
  export type JsonPrimitive = null | string | number | boolean;
8
8
 
9
- export type JsonObject = {
10
- [key: string]: Json;
11
- };
9
+ export type JsonObject = Record<string, Json>;
12
10
 
13
11
  export type JsonArray = Json[];
14
12
 
15
13
  export type Json = JsonPrimitive | JsonObject | JsonArray;
16
14
 
15
+
16
+ export type JsonStringifyablePrimitive = null | undefined | string | number | boolean;
17
+
18
+ export type JsonStringifyableObject = Record<string, JsonStringifyable>;
19
+
20
+ export type JsonStringifyableArray = JsonStringifyable[];
21
+
22
+ export type JsonStringifyable = JsonStringifyablePrimitive | JsonStringifyableObject | JsonStringifyableArray | { toJSON(): JsonStringifyable };
23
+
17
24
  /*
18
25
  * Param typing (like json but it supports dates if paramsSerializer is set to extended mode)
19
26
  */
@@ -49,7 +56,7 @@ export type LissaOptionsInit = Omit<RequestInit, 'method' | 'body'> & {
49
56
  timeout?: number;
50
57
  onUploadProgress?: (uploaded: number, total: number) => void;
51
58
  onDownloadProgress?: (downloaded: number, total: number) => void;
52
- body?: BodyInit | JsonObject;
59
+ body?: BodyInit | JsonStringifyableObject;
53
60
  };
54
61
 
55
62
  export type LissaOptions = Omit<LissaOptionsInit, 'headers'> & {
@@ -140,7 +147,7 @@ export declare class LissaRequest extends Promise<ResultValue> {
140
147
  *
141
148
  * The body gets json stringified if it is a plain object
142
149
  */
143
- body(body: BodyInit | JsonObject): LissaRequest;
150
+ body(body: BodyInit | JsonStringifyableObject): LissaRequest;
144
151
 
145
152
  /**
146
153
  * Set request timeout in milliseconds
@@ -207,7 +214,7 @@ interface MakeRequest {
207
214
  */
208
215
  post(
209
216
  url?: string,
210
- body?: BodyInit | JsonObject,
217
+ body?: BodyInit | JsonStringifyableObject,
211
218
  options?: Omit<LissaOptionsInit, 'method' | 'url' | 'body'>
212
219
  ): LissaRequest;
213
220
 
@@ -216,7 +223,7 @@ interface MakeRequest {
216
223
  */
217
224
  put(
218
225
  url?: string,
219
- body?: BodyInit | JsonObject,
226
+ body?: BodyInit | JsonStringifyableObject,
220
227
  options?: Omit<LissaOptionsInit, 'method' | 'url' | 'body'>
221
228
  ): LissaRequest;
222
229
 
@@ -225,7 +232,7 @@ interface MakeRequest {
225
232
  */
226
233
  patch(
227
234
  url?: string,
228
- body?: BodyInit | JsonObject,
235
+ body?: BodyInit | JsonStringifyableObject,
229
236
  options?: Omit<LissaOptionsInit, 'method' | 'url' | 'body'>
230
237
  ): LissaRequest;
231
238
 
@@ -421,14 +428,14 @@ export declare const retry: (options?: RetryOptions) => Plugin;
421
428
 
422
429
  export type CustomRetryError = {
423
430
  /** custom retry type have to be returned by shouldRetry hook */
424
- [K in `on${string}`]: number;
431
+ [K in `@${string}`]: number;
425
432
  };
426
433
 
427
434
  export type RetryOptions = CustomRetryError & {
428
- onConnectionError?: number;
429
- onGatewayError?: number;
430
- on429?: number;
431
- onServerError?: number;
435
+ '@ConnectionError'?: number;
436
+ '@GatewayError'?: number;
437
+ '@429'?: number;
438
+ '@ServerError'?: number;
432
439
 
433
440
  /**
434
441
  * Decide if the occurred error should trigger a retry.
@@ -436,8 +443,9 @@ export type RetryOptions = CustomRetryError & {
436
443
  * The given errorType helps preselecting error types. Return false to not
437
444
  * trigger a retry. Return nothing if the given errorType is correct. Return
438
445
  * a string to redefine the errorType or use a custom one. The number of
439
- * maximum retries can be configured as `on${errorType}`. Return "CustomError"
440
- * and define the retries as { onCustomError: 3 }
446
+ * maximum retries can be configured as `on${errorType}` or `@${errorType}`.
447
+ * Return "CustomError" and define the retries as { onCustomError: 3 } or
448
+ * as { '@CustomError': 3 }.
441
449
  */
442
450
  shouldRetry?: (
443
451
  errorType: void | 'ConnectionError' | 'GatewayError' | '429' | 'ServerError',
@@ -42,7 +42,7 @@ export default (options = {}) => (lissa) => {
42
42
  }
43
43
 
44
44
  // Return nothing to hand over the error to the next onError hook
45
- if (retry.attempt > (options[`on${errorType}`] || 0)) return;
45
+ if (retry.attempt > (options[`@${errorType}`] ?? options[`on${errorType}`] ?? 0)) return;
46
46
 
47
47
  await new Promise(resolve => setTimeout(resolve, retry.delay));
48
48
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lissa",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "A lightweight, extensible HTTP client for modern JavaScript applications with fluent api syntax, hooks, plugins and more.",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",