@hyper-fetch/core 2.0.0 → 3.0.0

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 (109) hide show
  1. package/README.md +14 -13
  2. package/dist/adapter/adapter.bindings.d.ts +25 -0
  3. package/dist/adapter/adapter.browser.d.ts +2 -0
  4. package/dist/{client/fetch.client.constants.d.ts → adapter/adapter.constants.d.ts} +0 -0
  5. package/dist/adapter/adapter.d.ts +2 -0
  6. package/dist/adapter/adapter.server.d.ts +2 -0
  7. package/dist/adapter/adapter.types.d.ts +57 -0
  8. package/dist/{client/fetch.client.utils.d.ts → adapter/adapter.utils.d.ts} +3 -3
  9. package/dist/adapter/index.d.ts +7 -0
  10. package/dist/cache/cache.d.ts +9 -9
  11. package/dist/cache/cache.types.d.ts +4 -4
  12. package/dist/cache/cache.utils.d.ts +3 -3
  13. package/dist/{builder/builder.constants.d.ts → client/client.constants.d.ts} +0 -0
  14. package/dist/client/client.d.ts +142 -0
  15. package/dist/client/client.types.d.ts +41 -0
  16. package/dist/client/client.utils.d.ts +10 -0
  17. package/dist/client/index.d.ts +4 -6
  18. package/dist/dispatcher/dispatcher.d.ts +23 -23
  19. package/dist/dispatcher/dispatcher.events.d.ts +8 -8
  20. package/dist/dispatcher/dispatcher.types.d.ts +10 -10
  21. package/dist/dispatcher/dispatcher.utils.d.ts +5 -5
  22. package/dist/effect/index.d.ts +2 -2
  23. package/dist/effect/request.effect.d.ts +14 -0
  24. package/dist/effect/request.effect.types.d.ts +32 -0
  25. package/dist/index.cjs.js +1 -1
  26. package/dist/index.cjs.js.map +4 -4
  27. package/dist/index.d.ts +3 -3
  28. package/dist/index.esm.js +1 -1
  29. package/dist/index.esm.js.map +4 -4
  30. package/dist/managers/index.d.ts +1 -1
  31. package/dist/managers/logger/logger.manager.d.ts +5 -5
  32. package/dist/managers/logger/logger.manager.types.d.ts +7 -7
  33. package/dist/managers/request/index.d.ts +4 -0
  34. package/dist/managers/request/request.manager.d.ts +43 -0
  35. package/dist/managers/request/request.manager.events.d.ts +36 -0
  36. package/dist/managers/{command/command.manager.types.d.ts → request/request.manager.types.d.ts} +6 -6
  37. package/dist/managers/{command/command.manager.utils.d.ts → request/request.manager.utils.d.ts} +0 -0
  38. package/dist/request/index.d.ts +3 -0
  39. package/dist/request/request.d.ts +98 -0
  40. package/dist/request/request.types.d.ts +202 -0
  41. package/dist/request/request.utils.d.ts +22 -0
  42. package/dist/types/fetch.types.d.ts +16 -16
  43. package/package.json +1 -1
  44. package/src/{client/fetch.client.bindings.ts → adapter/adapter.bindings.ts} +58 -58
  45. package/src/{client/fetch.client.browser.ts → adapter/adapter.browser.ts} +6 -6
  46. package/src/{client/fetch.client.constants.ts → adapter/adapter.constants.ts} +0 -0
  47. package/src/{client/fetch.client.server.ts → adapter/adapter.server.ts} +12 -12
  48. package/src/adapter/adapter.ts +8 -0
  49. package/src/adapter/adapter.types.ts +79 -0
  50. package/src/{client/fetch.client.utils.ts → adapter/adapter.utils.ts} +3 -3
  51. package/src/adapter/index.ts +7 -0
  52. package/src/cache/cache.ts +19 -19
  53. package/src/cache/cache.types.ts +4 -4
  54. package/src/cache/cache.utils.ts +6 -6
  55. package/src/{builder/builder.constants.ts → client/client.constants.ts} +0 -0
  56. package/src/client/client.ts +310 -0
  57. package/src/client/client.types.ts +52 -0
  58. package/src/{builder/builder.utils.ts → client/client.utils.ts} +34 -31
  59. package/src/client/index.ts +4 -6
  60. package/src/dispatcher/dispatcher.events.ts +11 -11
  61. package/src/dispatcher/dispatcher.ts +68 -68
  62. package/src/dispatcher/dispatcher.types.ts +10 -10
  63. package/src/dispatcher/dispatcher.utils.ts +7 -7
  64. package/src/effect/index.ts +2 -2
  65. package/src/effect/request.effect.ts +28 -0
  66. package/src/effect/request.effect.types.ts +35 -0
  67. package/src/index.ts +4 -4
  68. package/src/managers/index.ts +1 -1
  69. package/src/managers/logger/logger.manager.ts +8 -8
  70. package/src/managers/logger/logger.manager.types.ts +7 -7
  71. package/src/managers/request/index.ts +4 -0
  72. package/src/managers/{command/command.manager.events.ts → request/request.manager.events.ts} +47 -51
  73. package/src/managers/{command/command.manager.ts → request/request.manager.ts} +5 -5
  74. package/src/managers/request/request.manager.types.ts +25 -0
  75. package/src/managers/{command/command.manager.utils.ts → request/request.manager.utils.ts} +0 -0
  76. package/src/request/index.ts +3 -0
  77. package/src/{command/command.ts → request/request.ts} +188 -194
  78. package/src/request/request.types.ts +282 -0
  79. package/src/{command/command.utils.ts → request/request.utils.ts} +56 -53
  80. package/src/types/fetch.types.ts +18 -18
  81. package/dist/builder/builder.d.ts +0 -141
  82. package/dist/builder/builder.types.d.ts +0 -41
  83. package/dist/builder/builder.utils.d.ts +0 -10
  84. package/dist/builder/index.d.ts +0 -4
  85. package/dist/client/fetch.client.bindings.d.ts +0 -25
  86. package/dist/client/fetch.client.browser.d.ts +0 -2
  87. package/dist/client/fetch.client.d.ts +0 -2
  88. package/dist/client/fetch.client.server.d.ts +0 -2
  89. package/dist/client/fetch.client.types.d.ts +0 -57
  90. package/dist/command/command.d.ts +0 -98
  91. package/dist/command/command.types.d.ts +0 -202
  92. package/dist/command/command.utils.d.ts +0 -22
  93. package/dist/command/index.d.ts +0 -3
  94. package/dist/effect/fetch.effect.d.ts +0 -14
  95. package/dist/effect/fetch.effect.types.d.ts +0 -32
  96. package/dist/managers/command/command.manager.d.ts +0 -43
  97. package/dist/managers/command/command.manager.events.d.ts +0 -36
  98. package/dist/managers/command/index.d.ts +0 -4
  99. package/src/builder/builder.ts +0 -308
  100. package/src/builder/builder.types.ts +0 -53
  101. package/src/builder/index.ts +0 -4
  102. package/src/client/fetch.client.ts +0 -9
  103. package/src/client/fetch.client.types.ts +0 -83
  104. package/src/command/command.types.ts +0 -273
  105. package/src/command/index.ts +0 -3
  106. package/src/effect/fetch.effect.ts +0 -28
  107. package/src/effect/fetch.effect.types.ts +0 -35
  108. package/src/managers/command/command.manager.types.ts +0 -25
  109. package/src/managers/command/index.ts +0 -4
package/README.md CHANGED
@@ -42,33 +42,34 @@ particular `caching`, `queuing`, `persistence`, `offline first support`, `reques
42
42
 
43
43
  ## Features
44
44
 
45
- 🔮 **Simple setup** - [Read more](https://hyperfetch.bettertyped.com/guides/Basic/Setup)
45
+ 🔮 **Simple setup** - [Read more](https://hyperfetch.bettertyped.com/docs/guides/Basic/Setup)
46
46
 
47
- 🎯 **Request cancellation** - [Read more](https://hyperfetch.bettertyped.com/guides/Advanced/Cancellation)
47
+ 🎯 **Request cancellation** - [Read more](https://hyperfetch.bettertyped.com/docs/guides/Advanced/Cancellation)
48
48
 
49
- ✨ **Window Focus/Blur Events** - [Read more](https://hyperfetch.bettertyped.com/guides/React/Window%20Focus%20&%20Blur)
49
+ ✨ **Window Focus/Blur Events** -
50
+ [Read more](https://hyperfetch.bettertyped.com/docs/guides/React/Window%20Focus%20&%20Blur)
50
51
 
51
- 🚀 **Queueing** - [Read more](https://hyperfetch.bettertyped.com/guides/Advanced/Queueing)
52
+ 🚀 **Queueing** - [Read more](https://hyperfetch.bettertyped.com/docs/guides/Advanced/Queueing)
52
53
 
53
- 💎 **Automatic caching** - [Read more](https://hyperfetch.bettertyped.com/docs/Core/Cache)
54
+ 💎 **Automatic caching** - [Read more](https://hyperfetch.bettertyped.com/docs/documentation/Core/Cache)
54
55
 
55
- 🪄 **Persistance** - [Read more](https://hyperfetch.bettertyped.com/guides/Advanced/Persistence)
56
+ 🪄 **Persistence** - [Read more](https://hyperfetch.bettertyped.com/docs/guides/Advanced/Persistence)
56
57
 
57
- 🎊 **SSR Support** - [Read more](https://hyperfetch.bettertyped.com/docs/Getting%20Started/Environment)
58
+ 🎊 **SSR Support** - [Read more](https://hyperfetch.bettertyped.com/docs/documentation/Getting%20Started/Environment)
58
59
 
59
- 🔋 **Offline First** - [Read more](https://hyperfetch.bettertyped.com/guides/Advanced/Offline)
60
+ 🔋 **Offline First** - [Read more](https://hyperfetch.bettertyped.com/docs/guides/Advanced/Offline)
60
61
 
61
- 📡 **Built-in client** - [Read more](https://hyperfetch.bettertyped.com/docs/Core/Client)
62
+ 📡 **Built-in adapter** - [Read more](https://hyperfetch.bettertyped.com/docs/documentation/Core/Adapter)
62
63
 
63
- 🧪 **Easy to test** - [Read more](https://hyperfetch.bettertyped.com/docs/Getting%20Started/Testing)
64
+ 🧪 **Easy to test** - [Read more](https://hyperfetch.bettertyped.com/docs/documentation/Getting%20Started/Testing)
64
65
 
65
- 🎟 **Authentication** - [Read more](https://hyperfetch.bettertyped.com/guides/Basic/Authentication)
66
+ 🎟 **Authentication** - [Read more](https://hyperfetch.bettertyped.com/docs/guides/Basic/Authentication)
66
67
 
67
- 💡 **Prefetching** - [Read more](https://hyperfetch.bettertyped.com/guides/Advanced/Prefetching)
68
+ 💡 **Prefetching** - [Read more](https://hyperfetch.bettertyped.com/docs/guides/Advanced/Prefetching)
68
69
 
69
70
  ## Sources
70
71
 
71
- - #### [Installation](https://hyperfetch.bettertyped.com/docs/Getting%20Started/Installation)
72
+ - #### [Installation](https://hyperfetch.bettertyped.com/docs/documentation/Getting%20Started/Installation)
72
73
  - #### [Docs](https://hyperfetch.bettertyped.com/)
73
74
  - #### [API](https://hyperfetch.bettertyped.com/api/)
74
75
  - #### [NPM](https://www.npmjs.com/package/@hyper-fetch/core)
@@ -0,0 +1,25 @@
1
+ import { ResponseSuccessType, ResponseErrorType, ProgressDataType } from "adapter";
2
+ import { RequestInstance } from "request";
3
+ import { ExtractResponseType, ExtractErrorType } from "types";
4
+ export declare const getAdapterBindings: <ConfigType = any>(cmd: RequestInstance, requestId: string) => Promise<{
5
+ fullUrl: string;
6
+ headers: HeadersInit;
7
+ payload: string | FormData;
8
+ config: ConfigType;
9
+ getAbortController: () => AbortController;
10
+ getRequestStartTimestamp: () => number;
11
+ getResponseStartTimestamp: () => number;
12
+ createAbortListener: <T extends RequestInstance>(callback: () => void, resolve: (value: ResponseErrorType<ExtractErrorType<T>>) => void) => () => void;
13
+ onBeforeRequest: () => void;
14
+ onRequestStart: (progress?: ProgressDataType) => number;
15
+ onRequestProgress: (progress: ProgressDataType) => number;
16
+ onRequestEnd: () => number;
17
+ onResponseStart: (progress?: ProgressDataType) => number;
18
+ onResponseProgress: (progress: ProgressDataType) => number;
19
+ onResponseEnd: () => number;
20
+ onSuccess: <T_1 extends RequestInstance>(responseData: unknown, status: number, resolve: (value: ResponseErrorType<ExtractErrorType<T_1>>) => void) => Promise<ResponseSuccessType<ExtractResponseType<T_1>>>;
21
+ onAbortError: <T_2 extends RequestInstance>(resolve: (value: ResponseErrorType<ExtractErrorType<T_2>>) => void) => Promise<ResponseErrorType<ExtractErrorType<T_2>>>;
22
+ onTimeoutError: <T_3 extends RequestInstance>(resolve: (value: ResponseErrorType<ExtractErrorType<T_3>>) => void) => Promise<ResponseErrorType<ExtractErrorType<T_3>>>;
23
+ onUnexpectedError: <T_4 extends RequestInstance>(resolve: (value: ResponseErrorType<ExtractErrorType<T_4>>) => void) => Promise<ResponseErrorType<ExtractErrorType<T_4>>>;
24
+ onError: <T_5 extends RequestInstance>(error: Error | ExtractErrorType<T_5>, status: number, resolve: (value: ResponseErrorType<ExtractErrorType<T_5>>) => void) => Promise<ResponseErrorType<ExtractErrorType<T_5>>>;
25
+ }>;
@@ -0,0 +1,2 @@
1
+ import { AdapterType } from "adapter";
2
+ export declare const browserAdapter: AdapterType;
@@ -0,0 +1,2 @@
1
+ import { AdapterType } from "adapter";
2
+ export declare const adapter: AdapterType;
@@ -0,0 +1,2 @@
1
+ import { AdapterType } from "adapter";
2
+ export declare const serverAdapter: AdapterType;
@@ -0,0 +1,57 @@
1
+ import { RequestInstance } from "request";
2
+ export type AdapterType = (request: RequestInstance, requestId: string) => Promise<ResponseType<any, any>>;
3
+ export type AdapterOptionsType = Partial<XMLHttpRequest>;
4
+ export type AdapterPayloadMappingType = (data: unknown) => string | FormData;
5
+ export type ResponseType<GenericDataType, GenericErrorType> = [
6
+ GenericDataType | null,
7
+ GenericErrorType | null,
8
+ number | null
9
+ ];
10
+ export type ResponseSuccessType<GenericDataType> = [GenericDataType, null, number | null];
11
+ export type ResponseErrorType<GenericErrorType> = [null, GenericErrorType, number | null];
12
+ export type QueryParamValuesType = number | string | boolean | null | undefined;
13
+ export type QueryParamType = QueryParamValuesType | Array<QueryParamValuesType> | Record<string, QueryParamValuesType>;
14
+ export type QueryParamsType = Record<string, QueryParamType>;
15
+ export type HeaderMappingType = <T extends RequestInstance>(request: T) => HeadersInit;
16
+ export type AdapterHeadersProps = {
17
+ isFormData: boolean;
18
+ headers: HeadersInit | undefined;
19
+ };
20
+ export type QueryStringifyOptionsType = {
21
+ /**
22
+ * Strict URI encoding
23
+ */
24
+ strict?: boolean;
25
+ /**
26
+ * Encode keys and values
27
+ */
28
+ encode?: boolean;
29
+ /**
30
+ * Array encoding type
31
+ */
32
+ arrayFormat?: "bracket" | "index" | "comma" | "separator" | "bracket-separator" | "none";
33
+ /**
34
+ * Array format separator
35
+ */
36
+ arraySeparator?: string;
37
+ /**
38
+ * Skip keys with null values
39
+ */
40
+ skipNull?: boolean;
41
+ /**
42
+ * Skip keys with empty string
43
+ */
44
+ skipEmptyString?: boolean;
45
+ };
46
+ export type ProgressDataType = {
47
+ total?: number;
48
+ loaded?: number;
49
+ };
50
+ export type ProgressType = {
51
+ progress: number;
52
+ timeLeft: number | null;
53
+ sizeLeft: number;
54
+ total: number;
55
+ loaded: number;
56
+ startTimestamp: number;
57
+ };
@@ -1,8 +1,8 @@
1
- import { CommandInstance } from "command";
2
- import { ExtractError } from "types";
1
+ import { RequestInstance } from "request";
2
+ import { ExtractErrorType } from "types";
3
3
  export declare const getErrorMessage: (errorCase?: "timeout" | "abort" | "deleted") => Error;
4
4
  export declare const parseResponse: (response: string | unknown) => any;
5
- export declare const parseErrorResponse: <T extends CommandInstance>(response: unknown) => ExtractError<T>;
5
+ export declare const parseErrorResponse: <T extends RequestInstance>(response: unknown) => ExtractErrorType<T>;
6
6
  export declare const getUploadSize: (payload: FormData | string) => number;
7
7
  export declare const fileToBuffer: (file: File | Blob) => Promise<Uint8Array>;
8
8
  export declare const getStreamPayload: (payload: FormData | string | null) => string | Promise<(string | Uint8Array)[]>;
@@ -0,0 +1,7 @@
1
+ export * from "./adapter";
2
+ export * from "./adapter.types";
3
+ export * from "./adapter.utils";
4
+ export * from "./adapter.server";
5
+ export * from "./adapter.browser";
6
+ export * from "./adapter.bindings";
7
+ export * from "./adapter.constants";
@@ -1,20 +1,20 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node" />
3
3
  import EventEmitter from "events";
4
- import { ClientResponseType } from "client";
5
- import { BuilderInstance } from "builder";
6
- import { CommandResponseDetails } from "managers";
4
+ import { ResponseType } from "adapter";
5
+ import { ClientInstance } from "client";
6
+ import { ResponseDetailsType } from "managers";
7
7
  import { CacheOptionsType, CacheAsyncStorageType, CacheStorageType, getCacheEvents, CacheValueType } from "cache";
8
- import { CommandDump, CommandInstance } from "command";
8
+ import { RequestDump, RequestInstance } from "request";
9
9
  /**
10
10
  * Cache class handles the data exchange with the dispatchers.
11
11
  *
12
12
  * @note
13
- * Keys used to save the values are created dynamically on the Command class
13
+ * Keys used to save the values are created dynamically on the Request class
14
14
  *
15
15
  */
16
16
  export declare class Cache {
17
- builder: BuilderInstance;
17
+ client: ClientInstance;
18
18
  options?: CacheOptionsType;
19
19
  emitter: EventEmitter;
20
20
  events: ReturnType<typeof getCacheEvents>;
@@ -23,15 +23,15 @@ export declare class Cache {
23
23
  clearKey: string;
24
24
  garbageCollectors: Map<string, NodeJS.Timeout>;
25
25
  private logger;
26
- constructor(builder: BuilderInstance, options?: CacheOptionsType);
26
+ constructor(client: ClientInstance, options?: CacheOptionsType);
27
27
  /**
28
28
  * Set the cache data to the storage
29
- * @param command
29
+ * @param request
30
30
  * @param response
31
31
  * @param details
32
32
  * @returns
33
33
  */
34
- set: <Response_1, Error_1>(command: CommandInstance | CommandDump<CommandInstance>, response: ClientResponseType<Response_1, Error_1>, details: CommandResponseDetails) => void;
34
+ set: <Response_1, Error_1>(request: RequestInstance | RequestDump<RequestInstance>, response: ResponseType<Response_1, Error_1>, details: ResponseDetailsType) => void;
35
35
  /**
36
36
  * Get particular record from storage by cacheKey. It will trigger lazyStorage to emit lazy load event for reading it's data.
37
37
  * @param cacheKey
@@ -1,6 +1,6 @@
1
1
  import { Cache } from "cache";
2
- import { ClientResponseType } from "client";
3
- import { CommandResponseDetails } from "managers";
2
+ import { ResponseType } from "adapter";
3
+ import { ResponseDetailsType } from "managers";
4
4
  export type CacheOptionsType = {
5
5
  /**
6
6
  * Assign your custom sync storage
@@ -28,8 +28,8 @@ export type CacheOptionsType = {
28
28
  onDelete?: (key: string) => void;
29
29
  };
30
30
  export type CacheValueType<Response = any, Error = any> = {
31
- data: ClientResponseType<Response, Error>;
32
- details: CommandResponseDetails;
31
+ data: ResponseType<Response, Error>;
32
+ details: ResponseDetailsType;
33
33
  cacheTime: number;
34
34
  clearKey: string;
35
35
  garbageCollection: number;
@@ -1,6 +1,6 @@
1
- import { CommandInstance } from "command";
2
- import { ExtractClientReturnType } from "types";
3
- export declare const getCacheData: <T extends CommandInstance>(previousResponse: ExtractClientReturnType<T>, response: ExtractClientReturnType<T>) => ExtractClientReturnType<T>;
1
+ import { RequestInstance } from "request";
2
+ import { ExtractAdapterReturnType } from "types";
3
+ export declare const getCacheData: <T extends RequestInstance>(previousResponse: ExtractAdapterReturnType<T>, response: ExtractAdapterReturnType<T>) => ExtractAdapterReturnType<T>;
4
4
  export declare const getRevalidateEventKey: (key: string) => string;
5
5
  export declare const getCacheKey: (key: string) => string;
6
6
  export declare const getCacheIdKey: (key: string) => string;
@@ -0,0 +1,142 @@
1
+ import { AdapterType, AdapterOptionsType, ResponseType, QueryParamsType, QueryStringifyOptionsType, HeaderMappingType, AdapterPayloadMappingType } from "adapter";
2
+ import { ClientOptionsType, ClientInstance, ClientErrorType, StringifyCallbackType, RequestInterceptorType, ResponseInterceptorType } from "client";
3
+ import { Cache } from "cache";
4
+ import { Dispatcher } from "dispatcher";
5
+ import { RequestEffectInstance } from "effect";
6
+ import { Request, RequestOptionsType, RequestInstance } from "request";
7
+ import { AppManager, RequestManager, LoggerManager, SeverityType } from "managers";
8
+ /**
9
+ * **Client** is a class that allows you to configure the connection with the server and then use it to create
10
+ * requests which, when called using the appropriate method, will cause the server to be queried for the endpoint and
11
+ * method specified in the request.
12
+ * @position 1
13
+ */
14
+ export declare class Client<GlobalErrorType extends ClientErrorType = Error, AdapterOptions = AdapterOptionsType> {
15
+ options: ClientOptionsType;
16
+ readonly url: string;
17
+ debug: boolean;
18
+ __onErrorCallbacks: ResponseInterceptorType[];
19
+ __onSuccessCallbacks: ResponseInterceptorType[];
20
+ __onResponseCallbacks: ResponseInterceptorType[];
21
+ __onAuthCallbacks: RequestInterceptorType[];
22
+ __onRequestCallbacks: RequestInterceptorType[];
23
+ requestManager: RequestManager;
24
+ appManager: AppManager;
25
+ loggerManager: LoggerManager;
26
+ adapter: AdapterType;
27
+ cache: Cache;
28
+ fetchDispatcher: Dispatcher;
29
+ submitDispatcher: Dispatcher;
30
+ effects: RequestEffectInstance[];
31
+ queryParamsConfig?: QueryStringifyOptionsType;
32
+ adapterDefaultOptions?: (request: RequestInstance) => AdapterOptions;
33
+ requestDefaultOptions?: (options: RequestOptionsType<string, AdapterOptions>) => Partial<RequestOptionsType<string, AdapterOptions>>;
34
+ /**
35
+ * Method to stringify query params from objects.
36
+ */
37
+ stringifyQueryParams: StringifyCallbackType;
38
+ /**
39
+ * Method to get default headers and to map them based on the data format exchange, by default it handles FormData / JSON formats.
40
+ */
41
+ headerMapper: HeaderMappingType;
42
+ /**
43
+ * Method to get request data and transform them to the required format. It handles FormData and JSON by default.
44
+ */
45
+ payloadMapper: AdapterPayloadMappingType;
46
+ logger: import("managers").LoggerType;
47
+ constructor(options: ClientOptionsType);
48
+ /**
49
+ * This method allows to configure global defaults for the request configuration like method, auth, deduplication etc.
50
+ */
51
+ setRequestDefaultOptions: (callback: (request: RequestInstance) => Partial<RequestOptionsType<string, AdapterOptions>>) => Client<GlobalErrorType, AdapterOptions>;
52
+ setAdapterDefaultOptions: (callback: (request: RequestInstance) => AdapterOptions) => Client<GlobalErrorType, AdapterOptions>;
53
+ /**
54
+ * This method enables the logger usage and display the logs in console
55
+ */
56
+ setDebug: (debug: boolean) => Client<GlobalErrorType, AdapterOptions>;
57
+ /**
58
+ * Set the logger severity of the messages displayed to the console
59
+ */
60
+ setLoggerSeverity: (severity: SeverityType) => Client<GlobalErrorType, AdapterOptions>;
61
+ /**
62
+ * Set the new logger instance to the Client
63
+ */
64
+ setLogger: (callback: (Client: ClientInstance) => LoggerManager) => Client<GlobalErrorType, AdapterOptions>;
65
+ /**
66
+ * Set config for the query params stringify method, we can set here, among others, arrayFormat, skipNull, encode, skipEmptyString and more
67
+ */
68
+ setQueryParamsConfig: (queryParamsConfig: QueryStringifyOptionsType) => Client<GlobalErrorType, AdapterOptions>;
69
+ /**
70
+ * Set the custom query params stringify method to the Client
71
+ * @param stringifyFn Custom callback handling query params stringify
72
+ */
73
+ setStringifyQueryParams: (stringifyFn: StringifyCallbackType) => Client<GlobalErrorType, AdapterOptions>;
74
+ /**
75
+ * Set the custom header mapping function
76
+ */
77
+ setHeaderMapper: (headerMapper: HeaderMappingType) => Client<GlobalErrorType, AdapterOptions>;
78
+ /**
79
+ * Set the request payload mapping function which get triggered before request get send
80
+ */
81
+ setPayloadMapper: (payloadMapper: AdapterPayloadMappingType) => Client<GlobalErrorType, AdapterOptions>;
82
+ /**
83
+ * Set custom http adapter to handle graphql, rest, firebase or other
84
+ */
85
+ setAdapter: (callback: (Client: ClientInstance) => AdapterType) => Client<GlobalErrorType, AdapterOptions>;
86
+ /**
87
+ * Method of manipulating requests before sending the request. We can for example add custom header with token to the request which request had the auth set to true.
88
+ */
89
+ onAuth: (callback: RequestInterceptorType) => Client<GlobalErrorType, AdapterOptions>;
90
+ /**
91
+ * Method for intercepting error responses. It can be used for example to refresh tokens.
92
+ */
93
+ onError: <ErrorType = null>(callback: ResponseInterceptorType<any, GlobalErrorType | ErrorType>) => Client<GlobalErrorType, AdapterOptions>;
94
+ /**
95
+ * Method for intercepting success responses.
96
+ */
97
+ onSuccess: <ErrorType = null>(callback: ResponseInterceptorType<any, GlobalErrorType | ErrorType>) => Client<GlobalErrorType, AdapterOptions>;
98
+ /**
99
+ * Method of manipulating requests before sending the request.
100
+ */
101
+ onRequest: (callback: RequestInterceptorType) => Client<GlobalErrorType, AdapterOptions>;
102
+ /**
103
+ * Method for intercepting any responses.
104
+ */
105
+ onResponse: <ErrorType = null>(callback: ResponseInterceptorType<any, GlobalErrorType | ErrorType>) => Client<GlobalErrorType, AdapterOptions>;
106
+ /**
107
+ * Add persistent effects which trigger on the request lifecycle
108
+ */
109
+ addEffect: (effect: RequestEffectInstance | RequestEffectInstance[]) => this;
110
+ /**
111
+ * Remove effects from Client
112
+ */
113
+ removeEffect: (effect: RequestEffectInstance | string) => this;
114
+ /**
115
+ * Helper used by http adapter to apply the modifications on response error
116
+ */
117
+ __modifyAuth: (request: RequestInstance) => Promise<RequestInstance>;
118
+ /**
119
+ * Private helper to run async pre-request processing
120
+ */
121
+ __modifyRequest: (request: RequestInstance) => Promise<RequestInstance>;
122
+ /**
123
+ * Private helper to run async on-error response processing
124
+ */
125
+ __modifyErrorResponse: (response: ResponseType<any, GlobalErrorType>, request: RequestInstance) => Promise<ResponseType<any, GlobalErrorType>>;
126
+ /**
127
+ * Private helper to run async on-success response processing
128
+ */
129
+ __modifySuccessResponse: (response: ResponseType<any, GlobalErrorType>, request: RequestInstance) => Promise<ResponseType<any, GlobalErrorType>>;
130
+ /**
131
+ * Private helper to run async response processing
132
+ */
133
+ __modifyResponse: (response: ResponseType<any, GlobalErrorType>, request: RequestInstance) => Promise<ResponseType<any, GlobalErrorType>>;
134
+ /**
135
+ * Clears the Client instance and remove all listeners on it's dependencies
136
+ */
137
+ clear: () => void;
138
+ /**
139
+ * Create requests based on the Client setup
140
+ */
141
+ createRequest: <Response_1, Payload = undefined, LocalError extends ClientErrorType = undefined, QueryParams extends string | QueryParamsType = string | QueryParamsType>() => <EndpointType extends string>(params: RequestOptionsType<EndpointType, AdapterOptions>) => Request<Response_1, Payload, QueryParams, GlobalErrorType, LocalError, EndpointType, AdapterOptions, false, false, false, undefined>;
142
+ }
@@ -0,0 +1,41 @@
1
+ import { Cache } from "cache";
2
+ import { RequestInstance } from "request";
3
+ import { Dispatcher } from "dispatcher";
4
+ import { ResponseType, AdapterType, QueryParamsType } from "adapter";
5
+ import { Client } from "client";
6
+ import { AppManager } from "managers";
7
+ import { NegativeTypes } from "types";
8
+ export type ClientErrorType = Record<string, any> | string;
9
+ export type ClientInstance = Client<any, any>;
10
+ /**
11
+ * Configuration setup for the client
12
+ */
13
+ export type ClientOptionsType = {
14
+ /**
15
+ * Url to your server
16
+ */
17
+ url: string;
18
+ /**
19
+ * Custom adapter initialization prop
20
+ */
21
+ adapter?: AdapterType;
22
+ /**
23
+ * Custom cache initialization prop
24
+ */
25
+ cache?: <B extends ClientInstance, C extends Cache>(client: B) => C;
26
+ /**
27
+ * Custom app manager initialization prop
28
+ */
29
+ appManager?: <B extends ClientInstance, A extends AppManager>(client: B) => A;
30
+ /**
31
+ * Custom fetch dispatcher initialization prop
32
+ */
33
+ fetchDispatcher?: <B extends ClientInstance, D extends Dispatcher>(client: B) => D;
34
+ /**
35
+ * Custom submit dispatcher initialization prop
36
+ */
37
+ submitDispatcher?: <B extends ClientInstance, D extends Dispatcher>(client: B) => D;
38
+ };
39
+ export type RequestInterceptorType = (request: RequestInstance) => Promise<RequestInstance> | RequestInstance;
40
+ export type ResponseInterceptorType<Response = any, Error = any> = (response: ResponseType<Response, Error>, request: RequestInstance) => Promise<ResponseType<any, any>> | ResponseType<any, any>;
41
+ export type StringifyCallbackType = (queryParams: QueryParamsType | string | NegativeTypes) => string;
@@ -0,0 +1,10 @@
1
+ import { QueryParamsType, ResponseType, QueryStringifyOptionsType } from "adapter";
2
+ import { RequestInstance } from "request";
3
+ import { NegativeTypes } from "types";
4
+ import { RequestInterceptorType, ResponseInterceptorType } from "./client.types";
5
+ export declare const stringifyValue: (response: string | unknown) => string;
6
+ export declare const interceptRequest: (interceptors: RequestInterceptorType[], request: RequestInstance) => Promise<RequestInstance>;
7
+ export declare const interceptResponse: <GlobalErrorType>(interceptors: ResponseInterceptorType[], response: ResponseType<any, GlobalErrorType>, request: RequestInstance) => Promise<ResponseType<any, GlobalErrorType>>;
8
+ export declare const getAdapterHeaders: (request: RequestInstance) => HeadersInit;
9
+ export declare const getAdapterPayload: (data: unknown) => string | FormData;
10
+ export declare const stringifyQueryParams: (queryParams: QueryParamsType | string | NegativeTypes, options?: QueryStringifyOptionsType) => string;
@@ -1,6 +1,4 @@
1
- export * from "./fetch.client";
2
- export * from "./fetch.client.types";
3
- export * from "./fetch.client.utils";
4
- export * from "./fetch.client.browser";
5
- export * from "./fetch.client.bindings";
6
- export * from "./fetch.client.constants";
1
+ export * from "./client";
2
+ export * from "./client.utils";
3
+ export * from "./client.types";
4
+ export * from "./client.constants";
@@ -1,29 +1,29 @@
1
1
  /// <reference types="node" />
2
2
  import EventEmitter from "events";
3
- import { DispatcherData, DispatcherOptionsType, DispatcherStorageType, DispatcherDumpValueType, RunningRequestValueType } from "dispatcher";
4
- import { BuilderInstance } from "builder";
5
- import { CommandInstance } from "command";
3
+ import { QueueDataType, DispatcherOptionsType, DispatcherStorageType, DispatcherStorageValueType, RunningRequestValueType } from "dispatcher";
4
+ import { ClientInstance } from "client";
5
+ import { RequestInstance } from "request";
6
6
  /**
7
- * Dispatcher class was made to store controlled request Fetches, and firing them all-at-once or one-by-one in command queue.
7
+ * Dispatcher class was made to store controlled request Fetches, and firing them all-at-once or one-by-one in request queue.
8
8
  * Generally requests should be flushed at the same time, the queue provide mechanism to fire them in the order.
9
9
  */
10
10
  export declare class Dispatcher {
11
- builder: BuilderInstance;
11
+ client: ClientInstance;
12
12
  options?: DispatcherOptionsType;
13
13
  emitter: EventEmitter;
14
14
  events: {
15
- setDrained: <Command_1 extends CommandInstance>(queueKey: string, values: DispatcherData<Command_1>) => void;
16
- setQueueStatus: <Command_2 extends CommandInstance>(queueKey: string, values: DispatcherData<Command_2>) => void;
17
- setQueueChanged: <Command_3 extends CommandInstance>(queueKey: string, values: DispatcherData<Command_3>) => void;
18
- onDrained: <Command_4 extends CommandInstance>(queueKey: string, callback: (values: DispatcherData<Command_4>) => void) => VoidFunction;
19
- onQueueStatus: <Command_5 extends CommandInstance>(queueKey: string, callback: (values: DispatcherData<Command_5>) => void) => VoidFunction;
20
- onQueueChange: <Command_6 extends CommandInstance>(queueKey: string, callback: (values: DispatcherData<Command_6>) => void) => VoidFunction;
15
+ setDrained: <Request_1 extends RequestInstance>(queueKey: string, values: QueueDataType<Request_1>) => void;
16
+ setQueueStatus: <Request_2 extends RequestInstance>(queueKey: string, values: QueueDataType<Request_2>) => void;
17
+ setQueueChanged: <Request_3 extends RequestInstance>(queueKey: string, values: QueueDataType<Request_3>) => void;
18
+ onDrained: <Request_4 extends RequestInstance>(queueKey: string, callback: (values: QueueDataType<Request_4>) => void) => VoidFunction;
19
+ onQueueStatus: <Request_5 extends RequestInstance>(queueKey: string, callback: (values: QueueDataType<Request_5>) => void) => VoidFunction;
20
+ onQueueChange: <Request_6 extends RequestInstance>(queueKey: string, callback: (values: QueueDataType<Request_6>) => void) => VoidFunction;
21
21
  };
22
22
  storage: DispatcherStorageType;
23
23
  private requestCount;
24
24
  private runningRequests;
25
25
  private logger;
26
- constructor(builder: BuilderInstance, options?: DispatcherOptionsType);
26
+ constructor(client: ClientInstance, options?: DispatcherOptionsType);
27
27
  /**
28
28
  * Start request handling by queueKey
29
29
  */
@@ -43,11 +43,11 @@ export declare class Dispatcher {
43
43
  /**
44
44
  * Return queue state object
45
45
  */
46
- getQueue: <Command_1 extends CommandInstance = CommandInstance>(queueKey: string) => DispatcherData<Command_1>;
46
+ getQueue: <Request_1 extends RequestInstance = RequestInstance>(queueKey: string) => QueueDataType<Request_1>;
47
47
  /**
48
48
  * Return request from queue state
49
49
  */
50
- getRequest: <Command_1 extends CommandInstance = CommandInstance>(queueKey: string, requestId: string) => DispatcherDumpValueType<Command_1>;
50
+ getRequest: <Request_1 extends RequestInstance = RequestInstance>(queueKey: string, requestId: string) => DispatcherStorageValueType<Request_1>;
51
51
  /**
52
52
  * Get value of the active queue status based on the stopped status
53
53
  */
@@ -55,11 +55,11 @@ export declare class Dispatcher {
55
55
  /**
56
56
  * Add new element to storage
57
57
  */
58
- addQueueElement: <Command_1 extends CommandInstance = CommandInstance>(queueKey: string, dispatcherDump: DispatcherDumpValueType<Command_1>) => void;
58
+ addQueueElement: <Request_1 extends RequestInstance = RequestInstance>(queueKey: string, dispatcherDump: DispatcherStorageValueType<Request_1>) => void;
59
59
  /**
60
60
  * Set new queue storage value
61
61
  */
62
- setQueue: <Command_1 extends CommandInstance = CommandInstance>(queueKey: string, queue: DispatcherData<Command_1>) => DispatcherData<Command_1>;
62
+ setQueue: <Request_1 extends RequestInstance = RequestInstance>(queueKey: string, queue: QueueDataType<Request_1>) => QueueDataType<Request_1>;
63
63
  /**
64
64
  * Clear requests from queue cache
65
65
  */
@@ -102,7 +102,7 @@ export declare class Dispatcher {
102
102
  /**
103
103
  * Add request to the running requests list
104
104
  */
105
- addRunningRequest: (queueKey: string, requestId: string, command: CommandInstance) => void;
105
+ addRunningRequest: (queueKey: string, requestId: string, request: RequestInstance) => void;
106
106
  /**
107
107
  * Get the value based on the currently running requests
108
108
  */
@@ -136,20 +136,20 @@ export declare class Dispatcher {
136
136
  */
137
137
  incrementQueueRequestCount: (queueKey: string) => void;
138
138
  /**
139
- * Create storage element from command
139
+ * Create storage element from request
140
140
  */
141
- createStorageElement: <Command_1 extends CommandInstance>(command: Command_1) => DispatcherDumpValueType<Command_1>;
141
+ createStorageElement: <Request_1 extends RequestInstance>(request: Request_1) => DispatcherStorageValueType<Request_1>;
142
142
  /**
143
- * Add command to the dispatcher handler
143
+ * Add request to the dispatcher handler
144
144
  */
145
- add: (command: CommandInstance) => string;
145
+ add: (request: RequestInstance) => string;
146
146
  /**
147
147
  * Delete from the storage and cancel request
148
148
  */
149
- delete: (queueKey: string, requestId: string, abortKey: string) => DispatcherData<CommandInstance>;
149
+ delete: (queueKey: string, requestId: string, abortKey: string) => QueueDataType<RequestInstance>;
150
150
  /**
151
151
  * Request can run for some time, once it's done, we have to check if it's successful or if it was aborted
152
152
  * It can be different once the previous call was set as cancelled and removed from queue before this request got resolved
153
153
  */
154
- performRequest: (storageElement: DispatcherDumpValueType) => Promise<void | DispatcherData<CommandInstance>>;
154
+ performRequest: (storageElement: DispatcherStorageValueType) => Promise<void | QueueDataType<RequestInstance>>;
155
155
  }
@@ -1,11 +1,11 @@
1
1
  import EventEmitter from "events";
2
- import { DispatcherData } from "dispatcher";
3
- import { CommandInstance } from "command";
2
+ import { QueueDataType } from "dispatcher";
3
+ import { RequestInstance } from "request";
4
4
  export declare const getDispatcherEvents: (emitter: EventEmitter) => {
5
- setDrained: <Command extends CommandInstance>(queueKey: string, values: DispatcherData<Command>) => void;
6
- setQueueStatus: <Command_1 extends CommandInstance>(queueKey: string, values: DispatcherData<Command_1>) => void;
7
- setQueueChanged: <Command_2 extends CommandInstance>(queueKey: string, values: DispatcherData<Command_2>) => void;
8
- onDrained: <Command_3 extends CommandInstance>(queueKey: string, callback: (values: DispatcherData<Command_3>) => void) => VoidFunction;
9
- onQueueStatus: <Command_4 extends CommandInstance>(queueKey: string, callback: (values: DispatcherData<Command_4>) => void) => VoidFunction;
10
- onQueueChange: <Command_5 extends CommandInstance>(queueKey: string, callback: (values: DispatcherData<Command_5>) => void) => VoidFunction;
5
+ setDrained: <Request_1 extends RequestInstance>(queueKey: string, values: QueueDataType<Request_1>) => void;
6
+ setQueueStatus: <Request_2 extends RequestInstance>(queueKey: string, values: QueueDataType<Request_2>) => void;
7
+ setQueueChanged: <Request_3 extends RequestInstance>(queueKey: string, values: QueueDataType<Request_3>) => void;
8
+ onDrained: <Request_4 extends RequestInstance>(queueKey: string, callback: (values: QueueDataType<Request_4>) => void) => VoidFunction;
9
+ onQueueStatus: <Request_5 extends RequestInstance>(queueKey: string, callback: (values: QueueDataType<Request_5>) => void) => VoidFunction;
10
+ onQueueChange: <Request_6 extends RequestInstance>(queueKey: string, callback: (values: QueueDataType<Request_6>) => void) => VoidFunction;
11
11
  };
@@ -1,31 +1,31 @@
1
1
  import { Dispatcher } from "dispatcher";
2
- import { CommandDump, CommandInstance } from "command";
2
+ import { RequestDump, RequestInstance } from "request";
3
3
  export type DispatcherOptionsType = {
4
4
  storage?: DispatcherStorageType;
5
5
  onInitialization?: (dispatcherInstance: Dispatcher) => void;
6
- onUpdateStorage?: <Command extends CommandInstance>(queueKey: string, data: DispatcherData<Command>) => void;
7
- onDeleteFromStorage?: <Command extends CommandInstance>(queueKey: string, data: DispatcherData<Command>) => void;
6
+ onUpdateStorage?: <Request extends RequestInstance>(queueKey: string, data: QueueDataType<Request>) => void;
7
+ onDeleteFromStorage?: <Request extends RequestInstance>(queueKey: string, data: QueueDataType<Request>) => void;
8
8
  onClearStorage?: (dispatcherInstance: Dispatcher) => void;
9
9
  };
10
- export type DispatcherDumpValueType<Command extends CommandInstance = CommandInstance> = {
10
+ export type DispatcherStorageValueType<Request extends RequestInstance = RequestInstance> = {
11
11
  requestId: string;
12
- commandDump: CommandDump<Command>;
12
+ requestDump: RequestDump<Request>;
13
13
  retries: number;
14
14
  timestamp: number;
15
15
  stopped: boolean;
16
16
  };
17
- export type DispatcherData<Command extends CommandInstance = CommandInstance> = {
18
- requests: DispatcherDumpValueType<Command>[];
17
+ export type QueueDataType<Request extends RequestInstance = RequestInstance> = {
18
+ requests: DispatcherStorageValueType<Request>[];
19
19
  stopped: boolean;
20
20
  };
21
21
  export type DispatcherStorageType = {
22
- set: <Command extends CommandInstance = CommandInstance>(key: string, data: DispatcherData<Command>) => void;
23
- get: <Command extends CommandInstance = CommandInstance>(key: string) => DispatcherData<Command> | undefined;
22
+ set: <Request extends RequestInstance = RequestInstance>(key: string, data: QueueDataType<Request>) => void;
23
+ get: <Request extends RequestInstance = RequestInstance>(key: string) => QueueDataType<Request> | undefined;
24
24
  keys: () => string[] | IterableIterator<string>;
25
25
  delete: (key: string) => void;
26
26
  clear: () => void;
27
27
  };
28
28
  export type RunningRequestValueType = {
29
29
  requestId: string;
30
- command: CommandInstance;
30
+ request: RequestInstance;
31
31
  };