lissa 1.0.0 → 1.0.2

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.
Files changed (2) hide show
  1. package/lib/index.d.ts +41 -41
  2. package/package.json +1 -1
package/lib/index.d.ts CHANGED
@@ -4,39 +4,39 @@ import { RequestInit, HeadersInit, BodyInit, Headers } from 'undici-types';
4
4
  * General json typing
5
5
  */
6
6
 
7
- type JsonPrimitive = null | string | number | boolean;
7
+ export type JsonPrimitive = null | string | number | boolean;
8
8
 
9
- type JsonObject = {
9
+ export type JsonObject = {
10
10
  [key: string]: Json;
11
11
  };
12
12
 
13
- type JsonArray = Json[];
13
+ export type JsonArray = Json[];
14
14
 
15
- type Json = JsonPrimitive | JsonObject | JsonArray;
15
+ export type Json = JsonPrimitive | JsonObject | JsonArray;
16
16
 
17
17
  /*
18
18
  * Param typing (like json but it supports dates if paramsSerializer is set to extended mode)
19
19
  */
20
20
 
21
- type ParamPrimitive = null | string | number | bigint | boolean | Date;
21
+ export type ParamPrimitive = null | string | number | bigint | boolean | Date;
22
22
 
23
- type ParamObject = {
23
+ export type ParamObject = {
24
24
  [key: string]: ParamValue;
25
25
  };
26
26
 
27
- type ParamArray = ParamValue[];
27
+ export type ParamArray = ParamValue[];
28
28
 
29
- type ParamValue = ParamPrimitive | ParamObject | ParamArray;
29
+ export type ParamValue = ParamPrimitive | ParamObject | ParamArray;
30
30
 
31
- type Params = ParamObject;
31
+ export type Params = ParamObject;
32
32
 
33
33
  /*
34
34
  * Input and output types
35
35
  */
36
36
 
37
- type HttpMethod = 'get' | 'post' | 'put' | 'patch' | 'delete' | (string & {});
37
+ export type HttpMethod = 'get' | 'post' | 'put' | 'patch' | 'delete' | (string & {});
38
38
 
39
- type LissaOptionsInit = Omit<RequestInit, 'method' | 'body'> & {
39
+ export type LissaOptionsInit = Omit<RequestInit, 'method' | 'body'> & {
40
40
  adapter?: 'fetch' | 'xhr';
41
41
  baseURL?: string;
42
42
  url?: string;
@@ -52,12 +52,12 @@ type LissaOptionsInit = Omit<RequestInit, 'method' | 'body'> & {
52
52
  body?: BodyInit | JsonObject;
53
53
  };
54
54
 
55
- type LissaOptions = Omit<LissaOptionsInit, 'headers'> & {
55
+ export type LissaOptions = Omit<LissaOptionsInit, 'headers'> & {
56
56
  headers: Headers
57
57
  params: Params;
58
58
  };
59
59
 
60
- type DefaultOptionsInit = LissaOptionsInit & {
60
+ export type DefaultOptionsInit = LissaOptionsInit & {
61
61
  get?: LissaOptionsInit;
62
62
  post?: LissaOptionsInit;
63
63
  put?: LissaOptionsInit;
@@ -65,7 +65,7 @@ type DefaultOptionsInit = LissaOptionsInit & {
65
65
  delete?: LissaOptionsInit;
66
66
  };
67
67
 
68
- type DefaultOptions = LissaOptions & {
68
+ export type DefaultOptions = LissaOptions & {
69
69
  get: LissaOptions;
70
70
  post: LissaOptions;
71
71
  put: LissaOptions;
@@ -73,12 +73,12 @@ type DefaultOptions = LissaOptions & {
73
73
  delete: LissaOptions;
74
74
  };
75
75
 
76
- type FetchArguments = {
76
+ export type FetchArguments = {
77
77
  url: URL,
78
78
  options: Omit<RequestInit, 'headers'> & { headers: Headers },
79
79
  };
80
80
 
81
- type LissaResult = {
81
+ export type LissaResult = {
82
82
  options: LissaOptions;
83
83
  request: FetchArguments;
84
84
  response: Response;
@@ -87,18 +87,18 @@ type LissaResult = {
87
87
  data: null | string | Json | File | ReadableStream | Blob;
88
88
  };
89
89
 
90
- type GeneralErrorResponse = Error & {
90
+ export type GeneralErrorResponse = Error & {
91
91
  options: LissaOptions;
92
92
  request: FetchArguments;
93
93
  };
94
94
 
95
- type ResultValue = LissaResult | Exclude<any, undefined>;
95
+ export type ResultValue = LissaResult | Exclude<any, undefined>;
96
96
 
97
97
  /*
98
98
  * Interfaces
99
99
  */
100
100
 
101
- declare class LissaRequest extends Promise<ResultValue> {
101
+ export declare class LissaRequest extends Promise<ResultValue> {
102
102
  readonly options: LissaOptions;
103
103
 
104
104
  /**
@@ -293,9 +293,9 @@ interface MakeRequest {
293
293
  ): LissaRequest;
294
294
  }
295
295
 
296
- type Plugin = (lissa: Lissa) => void;
296
+ export type Plugin = (lissa: Lissa) => void;
297
297
 
298
- interface Lissa extends MakeRequest {
298
+ export interface Lissa extends MakeRequest {
299
299
  /**
300
300
  * Modify the base options directly.
301
301
  *
@@ -417,18 +417,18 @@ export declare class ResponseError extends Error {
417
417
  *
418
418
  * Retry requests on connection errors or server errors
419
419
  */
420
- export declare const retry: (options: RetryOptions) => Plugin;
420
+ export declare const retry: (options?: RetryOptions) => Plugin;
421
421
 
422
- type CustomRetryError = {
422
+ export type CustomRetryError = {
423
423
  /** custom retry type have to be returned by shouldRetry hook */
424
424
  [K in `on${string}`]: number;
425
425
  };
426
426
 
427
- type RetryOptions = CustomRetryError & {
428
- onConnectionError: number;
429
- onGatewayError: number;
430
- on429: number;
431
- onServerError: number;
427
+ export type RetryOptions = CustomRetryError & {
428
+ onConnectionError?: number;
429
+ onGatewayError?: number;
430
+ on429?: number;
431
+ onServerError?: number;
432
432
 
433
433
  /**
434
434
  * Decide if the occurred error should trigger a retry.
@@ -439,38 +439,38 @@ type RetryOptions = CustomRetryError & {
439
439
  * maximum retries can be configured as `on${errorType}`. Return "CustomError"
440
440
  * and define the retries as { onCustomError: 3 }
441
441
  */
442
- shouldRetry(
442
+ shouldRetry?: (
443
443
  errorType: void | 'ConnectionError' | 'GatewayError' | '429' | 'ServerError',
444
444
  error: ResponseError | ConnectionError | GeneralErrorResponse,
445
- ): void | false | string;
445
+ ) => void | false | string;
446
446
 
447
447
  /**
448
448
  * Hook into the retry logic after the retry is triggered and before the delay
449
449
  * is awaited. Use beforeRetry e. g. if you want to change how long the delay
450
450
  * should be or to notify a customer that the connection is lost.
451
451
  */
452
- beforeRetry(
452
+ beforeRetry?: (
453
453
  retry: { attempt: number, delay: number },
454
454
  error: ResponseError | ConnectionError | GeneralErrorResponse,
455
- ): void | { attempt: number, delay: number };
455
+ ) => void | { attempt: number, delay: number };
456
456
 
457
457
  /**
458
458
  * Hook into the retry logic after the delay is awaited and before the request
459
459
  * gets resend. Use onRetry e. g. if you want to log that a retry is running now
460
460
  */
461
- onRetry(
461
+ onRetry?: (
462
462
  retry: { attempt: number, delay: number },
463
463
  error: ResponseError | ConnectionError | GeneralErrorResponse,
464
- ): void;
464
+ ) => void;
465
465
 
466
466
  /**
467
467
  * Hook into the retry logic after a request was successful. Use onSuccess
468
468
  * e. g. if you want to dismiss a connection lost notification
469
469
  */
470
- onSuccess(
470
+ onSuccess?: (
471
471
  retry: { attempt: number, delay: number },
472
472
  res: ResultValue,
473
- ): void;
473
+ ) => void;
474
474
  };
475
475
 
476
476
  /**
@@ -478,26 +478,26 @@ type RetryOptions = CustomRetryError & {
478
478
  *
479
479
  * Aborts leading or trailing requests to the same endpoint (depends on configured strategy [default is leading])
480
480
  */
481
- export declare const dedupe: (options: DedupeOptions) => Plugin;
481
+ export declare const dedupe: (options?: DedupeOptions) => Plugin;
482
482
 
483
- type DedupeOptions = {
483
+ export type DedupeOptions = {
484
484
  /**
485
485
  * Which request methods should be deduped. Defaults to "get"
486
486
  */
487
- methods: HttpMethod[];
487
+ methods?: HttpMethod[];
488
488
 
489
489
  /**
490
490
  * How to build the endpoint identifier. Defaults to url + method.
491
491
  * Return false to skip dedupe logic.
492
492
  */
493
- getIdentifier: (options: LissaOptions) => any;
493
+ getIdentifier?: (options: LissaOptions) => any;
494
494
 
495
495
  /**
496
496
  * Define default strategy. Abort leading requests on new request or abort
497
497
  * trailing new requests until first finishes. Can be also configured
498
498
  * individually by adding a dedupe param to the request options.
499
499
  */
500
- defaultStrategy: 'leading' | 'trailing';
500
+ defaultStrategy?: 'leading' | 'trailing';
501
501
  };
502
502
 
503
503
  // Named exports are also params of the default export
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lissa",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
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",