@hyper-fetch/core 1.6.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 (118) hide show
  1. package/.eslintrc.json +7 -0
  2. package/README.md +83 -0
  3. package/dist/builder/builder.constants.d.ts +9 -0
  4. package/dist/builder/builder.d.ts +141 -0
  5. package/dist/builder/builder.types.d.ts +45 -0
  6. package/dist/builder/builder.utils.d.ts +10 -0
  7. package/dist/builder/index.d.ts +4 -0
  8. package/dist/cache/cache.d.ts +76 -0
  9. package/dist/cache/cache.events.d.ts +28 -0
  10. package/dist/cache/cache.types.d.ts +49 -0
  11. package/dist/cache/cache.utils.d.ts +6 -0
  12. package/dist/cache/index.d.ts +4 -0
  13. package/dist/client/fetch.client.bindings.d.ts +25 -0
  14. package/dist/client/fetch.client.constants.d.ts +1 -0
  15. package/dist/client/fetch.client.d.ts +2 -0
  16. package/dist/client/fetch.client.types.d.ts +57 -0
  17. package/dist/client/fetch.client.utils.d.ts +5 -0
  18. package/dist/client/index.d.ts +5 -0
  19. package/dist/command/command.d.ts +87 -0
  20. package/dist/command/command.types.d.ts +196 -0
  21. package/dist/command/command.utils.d.ts +22 -0
  22. package/dist/command/index.d.ts +3 -0
  23. package/dist/constants/http.constants.d.ts +7 -0
  24. package/dist/constants/time.constants.d.ts +11 -0
  25. package/dist/dispatcher/dispatcher.constants.d.ts +6 -0
  26. package/dist/dispatcher/dispatcher.d.ts +155 -0
  27. package/dist/dispatcher/dispatcher.events.d.ts +11 -0
  28. package/dist/dispatcher/dispatcher.types.d.ts +31 -0
  29. package/dist/dispatcher/dispatcher.utils.d.ts +10 -0
  30. package/dist/dispatcher/index.d.ts +5 -0
  31. package/dist/effect/fetch.effect.d.ts +14 -0
  32. package/dist/effect/fetch.effect.types.d.ts +32 -0
  33. package/dist/effect/index.d.ts +2 -0
  34. package/dist/index.cjs.js +2 -0
  35. package/dist/index.cjs.js.map +7 -0
  36. package/dist/index.d.ts +10 -0
  37. package/dist/index.esm.js +2 -0
  38. package/dist/index.esm.js.map +7 -0
  39. package/dist/managers/app/app.manager.constants.d.ts +9 -0
  40. package/dist/managers/app/app.manager.d.ts +35 -0
  41. package/dist/managers/app/app.manager.events.d.ts +11 -0
  42. package/dist/managers/app/app.manager.types.d.ts +7 -0
  43. package/dist/managers/app/app.manager.utils.d.ts +4 -0
  44. package/dist/managers/app/index.d.ts +5 -0
  45. package/dist/managers/command/command.manager.d.ts +43 -0
  46. package/dist/managers/command/command.manager.events.d.ts +36 -0
  47. package/dist/managers/command/command.manager.types.d.ts +23 -0
  48. package/dist/managers/command/command.manager.utils.d.ts +16 -0
  49. package/dist/managers/command/index.d.ts +4 -0
  50. package/dist/managers/index.d.ts +3 -0
  51. package/dist/managers/logger/index.d.ts +4 -0
  52. package/dist/managers/logger/logger.manager.constants.d.ts +4 -0
  53. package/dist/managers/logger/logger.manager.d.ts +19 -0
  54. package/dist/managers/logger/logger.manager.types.d.ts +30 -0
  55. package/dist/managers/logger/logger.manager.utils.d.ts +3 -0
  56. package/dist/types/fetch.types.d.ts +15 -0
  57. package/dist/types/helpers.types.d.ts +11 -0
  58. package/dist/types/http.types.d.ts +1 -0
  59. package/dist/types/index.d.ts +3 -0
  60. package/dist/utils/index.d.ts +1 -0
  61. package/dist/utils/uuid.utils.d.ts +1 -0
  62. package/package.json +60 -0
  63. package/src/builder/builder.constants.ts +9 -0
  64. package/src/builder/builder.ts +309 -0
  65. package/src/builder/builder.types.ts +57 -0
  66. package/src/builder/builder.utils.ts +178 -0
  67. package/src/builder/index.ts +4 -0
  68. package/src/cache/cache.events.ts +44 -0
  69. package/src/cache/cache.ts +221 -0
  70. package/src/cache/cache.types.ts +56 -0
  71. package/src/cache/cache.utils.ts +29 -0
  72. package/src/cache/index.ts +4 -0
  73. package/src/client/fetch.client.bindings.ts +290 -0
  74. package/src/client/fetch.client.constants.ts +3 -0
  75. package/src/client/fetch.client.ts +98 -0
  76. package/src/client/fetch.client.types.ts +83 -0
  77. package/src/client/fetch.client.utils.ts +28 -0
  78. package/src/client/index.ts +5 -0
  79. package/src/command/command.ts +539 -0
  80. package/src/command/command.types.ts +268 -0
  81. package/src/command/command.utils.ts +179 -0
  82. package/src/command/index.ts +3 -0
  83. package/src/constants/http.constants.ts +7 -0
  84. package/src/constants/time.constants.ts +11 -0
  85. package/src/dispatcher/dispatcher.constants.ts +6 -0
  86. package/src/dispatcher/dispatcher.events.ts +42 -0
  87. package/src/dispatcher/dispatcher.ts +596 -0
  88. package/src/dispatcher/dispatcher.types.ts +39 -0
  89. package/src/dispatcher/dispatcher.utils.ts +55 -0
  90. package/src/dispatcher/index.ts +5 -0
  91. package/src/effect/fetch.effect.ts +28 -0
  92. package/src/effect/fetch.effect.types.ts +35 -0
  93. package/src/effect/index.ts +2 -0
  94. package/src/index.ts +12 -0
  95. package/src/managers/app/app.manager.constants.ts +24 -0
  96. package/src/managers/app/app.manager.events.ts +34 -0
  97. package/src/managers/app/app.manager.ts +74 -0
  98. package/src/managers/app/app.manager.types.ts +8 -0
  99. package/src/managers/app/app.manager.utils.ts +34 -0
  100. package/src/managers/app/index.ts +5 -0
  101. package/src/managers/command/command.manager.events.ts +212 -0
  102. package/src/managers/command/command.manager.ts +68 -0
  103. package/src/managers/command/command.manager.types.ts +25 -0
  104. package/src/managers/command/command.manager.utils.ts +19 -0
  105. package/src/managers/command/index.ts +4 -0
  106. package/src/managers/index.ts +3 -0
  107. package/src/managers/logger/index.ts +4 -0
  108. package/src/managers/logger/logger.manager.constants.ts +24 -0
  109. package/src/managers/logger/logger.manager.ts +70 -0
  110. package/src/managers/logger/logger.manager.types.ts +35 -0
  111. package/src/managers/logger/logger.manager.utils.ts +27 -0
  112. package/src/types/fetch.types.ts +39 -0
  113. package/src/types/helpers.types.ts +15 -0
  114. package/src/types/http.types.ts +1 -0
  115. package/src/types/index.ts +3 -0
  116. package/src/utils/index.ts +1 -0
  117. package/src/utils/uuid.utils.ts +3 -0
  118. package/tsconfig.json +8 -0
package/.eslintrc.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": ["../../.eslintrc.json"],
3
+ "parserOptions": {
4
+ "project": ["./tsconfig.json", "./__tests__/tsconfig.json"]
5
+ },
6
+ "ignorePatterns": ["dist/"]
7
+ }
package/README.md ADDED
@@ -0,0 +1,83 @@
1
+ <h1 align="center">
2
+
3
+ ⚡ <br /> Hyper Fetch
4
+
5
+ </h1>
6
+
7
+ <p align="center">
8
+ <a href="https://bettertyped.com/">
9
+ <img src="https://custom-icon-badges.demolab.com/static/v1?label=&message=BetterTyped&color=333&logo=BT" />
10
+ </a>
11
+ <a href="https://github.com/BetterTyped/hyper-fetch">
12
+ <img src="https://custom-icon-badges.demolab.com/github/stars/BetterTyped/hyper-fetch?logo=star&color=118ab2" />
13
+ </a>
14
+ <a href="https://github.com/BetterTyped/hyper-fetch/blob/main/License.md">
15
+ <img src="https://custom-icon-badges.demolab.com/github/license/BetterTyped/hyper-fetch?logo=law&color=yellow" />
16
+ </a>
17
+ <a href="https://www.npmjs.com/package/@hyper-fetch/core">
18
+ <img src="https://custom-icon-badges.demolab.com/npm/v/@hyper-fetch/core.svg?logo=npm&color=e76f51" />
19
+ </a>
20
+ <a href="https://api.codeclimate.com/v1/badges/eade9435e75ecea0c004/test_coverage">
21
+ <img src="https://api.codeclimate.com/v1/badges/eade9435e75ecea0c004/test_coverage" />
22
+ </a>
23
+ <a href="https://github.com/BetterTyped/hyper-fetch">
24
+ <img src="https://custom-icon-badges.demolab.com/badge/typescript-%23007ACC.svg?logo=typescript&logoColor=white" />
25
+ </a>
26
+ <a href="https://github.com/BetterTyped/hyper-fetch">
27
+ <img src="https://custom-icon-badges.demolab.com/badge/-REST-informational?logo=rss&color=11b8cc" />
28
+ </a>
29
+ <a href="https://github.com/BetterTyped/hyper-fetch">
30
+ <img src="https://custom-icon-badges.demolab.com/badge/-GraphQL-E10098?logo=graphql&logoColor=white" />
31
+ </a>
32
+ <a href="https://gitter.im/hyper-fetch/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge">
33
+ <img src="https://custom-icon-badges.demolab.com/badge/chat%20-on%20gitter-brightgreen.svg?logo=gitter&color=blueviolet" />
34
+ </a>
35
+ <a href="https://www.npmjs.com/package/@hyper-fetch/core">
36
+ <img src="https://custom-icon-badges.demolab.com/bundlephobia/min/@hyper-fetch/core?color=64BC4B&logo=package" />
37
+ </a>
38
+ </p>
39
+
40
+ ## About
41
+
42
+ **`Hyper Fetch`** is a data-exchange framework. What makes it unique is the **typesafe design** and the **ease of use**.
43
+ This library is `backend and framework agnostic`, with aim to provide as many great and useful features as possible. In
44
+ particular `caching`, `queuing`, `persistence`, `offline first support`, `request deduplication`, `authentication`,
45
+ `progress tracking`, `structure and architecture` guidelines.
46
+
47
+ ## Features
48
+
49
+ 🔮 **Simple setup** - [Read more](https://hyperfetch.bettertyped.com/guides/Basic/Setup)
50
+
51
+ 🎯 **Request cancellation** - [Read more](https://hyperfetch.bettertyped.com/guides/Advanced/Cancellation)
52
+
53
+ ✨ **Window Focus/Blur Events** - [Read more](https://hyperfetch.bettertyped.com/guides/React/Window%20Focus%20&%20Blur)
54
+
55
+ 🚀 **Queueing** - [Read more](https://hyperfetch.bettertyped.com/guides/Advanced/Queueing)
56
+
57
+ 💎 **Automatic caching** - [Read more](https://hyperfetch.bettertyped.com/docs/Architecture/Cache)
58
+
59
+ 🪄 **Persistance** - [Read more](https://hyperfetch.bettertyped.com/guides/Advanced/Persistence)
60
+
61
+ 🎊 **SSR Support** - [Read more](https://hyperfetch.bettertyped.com/docs/Getting%20Started/Environment)
62
+
63
+ 🔋 **Offline First** - [Read more](https://hyperfetch.bettertyped.com/guides/Advanced/Offline)
64
+
65
+ 📡 **Built-in client** - [Read more](https://hyperfetch.bettertyped.com/docs/Architecture/Client)
66
+
67
+ 🧪 **Easy to test** - [Read more](https://hyperfetch.bettertyped.com/docs/Getting%20Started/Testing)
68
+
69
+ 🎟 **Authentication** - [Read more](https://hyperfetch.bettertyped.com/guides/Basic/Authentication)
70
+
71
+ 💡 **Prefetching** - [Read more](https://hyperfetch.bettertyped.com/guides/Advanced/Prefetching)
72
+
73
+ ## Sources
74
+
75
+ - #### [Installation](https://hyperfetch.bettertyped.com/docs/Getting%20Started/Installation)
76
+ - #### [Docs](https://hyperfetch.bettertyped.com/)
77
+ - #### [API](https://hyperfetch.bettertyped.com/api/)
78
+ - #### [NPM](https://www.npmjs.com/package/@hyper-fetch/core)
79
+ - #### [Guides](https://hyperfetch.bettertyped.com/guides/Basic/Setup)
80
+
81
+ ## Other Packages
82
+
83
+ - #### [React Hyper Fetch](https://github.com/BetterTyped/hyper-fetch/tree/main/packages/react)
@@ -0,0 +1,9 @@
1
+ export declare const stringifyDefaultOptions: {
2
+ readonly strict: true;
3
+ readonly encode: true;
4
+ readonly arrayFormat: "bracket";
5
+ readonly arraySeparator: "";
6
+ readonly sort: false;
7
+ readonly skipNull: true;
8
+ readonly skipEmptyString: true;
9
+ };
@@ -0,0 +1,141 @@
1
+ import { ClientType, ClientDefaultOptionsType, ClientResponseType, ClientQueryParamsType, QueryStringifyOptions, ClientHeaderMappingCallback, ClientPayloadMappingCallback } from "../client";
2
+ import { BuilderConfig, BuilderInstance, BuilderErrorType, StringifyCallbackType, RequestInterceptorCallback, ResponseInterceptorCallback } from "./";
3
+ import { Cache } from "../cache";
4
+ import { Dispatcher } from "../dispatcher";
5
+ import { FetchEffectInstance } from "../effect";
6
+ import { Command, CommandConfig, CommandInstance } from "../command";
7
+ import { AppManager, CommandManager, LoggerManager, SeverityType } from "../managers";
8
+ /**
9
+ * **Builder** is a class that allows you to configure the connection with the server and then use it to create
10
+ * commands which, when called using the appropriate method, will cause the server to be queried for the endpoint and
11
+ * method specified in the command.
12
+ */
13
+ export declare class Builder<GlobalErrorType extends BuilderErrorType = Error, RequestConfigType = ClientDefaultOptionsType> {
14
+ options: BuilderConfig;
15
+ readonly baseUrl: string;
16
+ readonly isNodeJS: boolean;
17
+ debug: boolean;
18
+ __onErrorCallbacks: ResponseInterceptorCallback[];
19
+ __onSuccessCallbacks: ResponseInterceptorCallback[];
20
+ __onResponseCallbacks: ResponseInterceptorCallback[];
21
+ __onAuthCallbacks: RequestInterceptorCallback[];
22
+ __onRequestCallbacks: RequestInterceptorCallback[];
23
+ commandManager: CommandManager;
24
+ appManager: AppManager;
25
+ loggerManager: LoggerManager;
26
+ client: ClientType;
27
+ cache: Cache;
28
+ fetchDispatcher: Dispatcher;
29
+ submitDispatcher: Dispatcher;
30
+ effects: FetchEffectInstance[];
31
+ requestConfig?: (command: CommandInstance) => RequestConfigType;
32
+ commandConfig?: (commandOptions: CommandConfig<string, RequestConfigType>) => Partial<CommandConfig<string, RequestConfigType>>;
33
+ queryParamsConfig?: QueryStringifyOptions;
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: ClientHeaderMappingCallback;
42
+ /**
43
+ * Method to get request data and transform them to the required format. It handles FormData and JSON by default.
44
+ */
45
+ payloadMapper: ClientPayloadMappingCallback;
46
+ logger: import("../managers").LoggerType;
47
+ constructor(options: BuilderConfig);
48
+ /**
49
+ * This method allows to configure global defaults for the command configuration like method, auth, deduplication etc.
50
+ */
51
+ setCommandConfig: (callback: (command: CommandInstance) => Partial<CommandConfig<string, RequestConfigType>>) => Builder<GlobalErrorType, RequestConfigType>;
52
+ /**
53
+ * This method enables the logger usage and display the logs in console
54
+ */
55
+ setDebug: (debug: boolean) => Builder<GlobalErrorType, RequestConfigType>;
56
+ /**
57
+ * Set the logger severity of the messages displayed to the console
58
+ */
59
+ setLoggerSeverity: (severity: SeverityType) => Builder<GlobalErrorType, RequestConfigType>;
60
+ /**
61
+ * Set the new logger instance to the builder
62
+ */
63
+ setLogger: (callback: (builder: BuilderInstance) => LoggerManager) => Builder<GlobalErrorType, RequestConfigType>;
64
+ /**
65
+ * Set config for the query params stringify method, we can set here, among others, arrayFormat, skipNull, encode, skipEmptyString and more
66
+ */
67
+ setQueryParamsConfig: (queryParamsConfig: QueryStringifyOptions) => Builder<GlobalErrorType, RequestConfigType>;
68
+ /**
69
+ * Set the custom query params stringify method to the builder
70
+ * @param stringifyFn Custom callback handling query params stringify
71
+ */
72
+ setStringifyQueryParams: (stringifyFn: StringifyCallbackType) => Builder<GlobalErrorType, RequestConfigType>;
73
+ /**
74
+ * Set the custom header mapping function
75
+ */
76
+ setHeaderMapper: (headerMapper: ClientHeaderMappingCallback) => Builder<GlobalErrorType, RequestConfigType>;
77
+ /**
78
+ * Set the request payload mapping function which get triggered before request get send
79
+ */
80
+ setPayloadMapper: (payloadMapper: ClientPayloadMappingCallback) => Builder<GlobalErrorType, RequestConfigType>;
81
+ /**
82
+ * Set custom http client to handle graphql, rest, firebase or other
83
+ */
84
+ setClient: (callback: (builder: BuilderInstance) => ClientType) => Builder<GlobalErrorType, RequestConfigType>;
85
+ /**
86
+ * Method of manipulating commands before sending the request. We can for example add custom header with token to the request which command had the auth set to true.
87
+ */
88
+ onAuth: (callback: RequestInterceptorCallback) => Builder<GlobalErrorType, RequestConfigType>;
89
+ /**
90
+ * Method for intercepting error responses. It can be used for example to refresh tokens.
91
+ */
92
+ onError: <ErrorType = null>(callback: ResponseInterceptorCallback<any, GlobalErrorType | ErrorType>) => Builder<GlobalErrorType, RequestConfigType>;
93
+ /**
94
+ * Method for intercepting success responses.
95
+ */
96
+ onSuccess: <ErrorType = null>(callback: ResponseInterceptorCallback<any, GlobalErrorType | ErrorType>) => Builder<GlobalErrorType, RequestConfigType>;
97
+ /**
98
+ * Method of manipulating commands before sending the request.
99
+ */
100
+ onRequest: (callback: RequestInterceptorCallback) => Builder<GlobalErrorType, RequestConfigType>;
101
+ /**
102
+ * Method for intercepting any responses.
103
+ */
104
+ onResponse: <ErrorType = null>(callback: ResponseInterceptorCallback<any, GlobalErrorType | ErrorType>) => Builder<GlobalErrorType, RequestConfigType>;
105
+ /**
106
+ * Add persistent effects which trigger on the request lifecycle
107
+ */
108
+ addEffect: (effect: FetchEffectInstance | FetchEffectInstance[]) => this;
109
+ /**
110
+ * Remove effects from builder
111
+ */
112
+ removeEffect: (effect: FetchEffectInstance | string) => this;
113
+ /**
114
+ * Create commands based on the builder setup
115
+ */
116
+ createCommand: <ResponseType_1, RequestDataType = undefined, LocalErrorType extends BuilderErrorType = undefined, QueryParamsType extends string | ClientQueryParamsType = string | ClientQueryParamsType>() => <EndpointType extends string>(params: CommandConfig<EndpointType, RequestConfigType>) => Command<ResponseType_1, RequestDataType, QueryParamsType, GlobalErrorType, LocalErrorType, EndpointType, RequestConfigType, false, false, false, undefined>;
117
+ /**
118
+ * Clears the builder instance and remove all listeners on it's dependencies
119
+ */
120
+ clear: () => void;
121
+ /**
122
+ * Helper used by http client to apply the modifications on response error
123
+ */
124
+ __modifyAuth: (command: CommandInstance) => Promise<CommandInstance>;
125
+ /**
126
+ * Private helper to run async pre-request processing
127
+ */
128
+ __modifyRequest: (command: CommandInstance) => Promise<CommandInstance>;
129
+ /**
130
+ * Private helper to run async on-error response processing
131
+ */
132
+ __modifyErrorResponse: (response: ClientResponseType<any, GlobalErrorType>, command: CommandInstance) => Promise<ClientResponseType<any, GlobalErrorType>>;
133
+ /**
134
+ * Private helper to run async on-success response processing
135
+ */
136
+ __modifySuccessResponse: (response: ClientResponseType<any, GlobalErrorType>, command: CommandInstance) => Promise<ClientResponseType<any, GlobalErrorType>>;
137
+ /**
138
+ * Private helper to run async response processing
139
+ */
140
+ __modifyResponse: (response: ClientResponseType<any, GlobalErrorType>, command: CommandInstance) => Promise<ClientResponseType<any, GlobalErrorType>>;
141
+ }
@@ -0,0 +1,45 @@
1
+ import { Cache } from "../cache";
2
+ import { CommandInstance } from "../command";
3
+ import { Dispatcher } from "../dispatcher";
4
+ import { ClientResponseType, ClientType, ClientQueryParamsType } from "../client";
5
+ import { Builder } from "./";
6
+ import { AppManager } from "../managers";
7
+ import { NegativeTypes } from "../types";
8
+ /**
9
+ * Configuration setup for the builder
10
+ */
11
+ export declare type BuilderConfig = {
12
+ /**
13
+ * Url to your server
14
+ */
15
+ baseUrl: string;
16
+ /**
17
+ * Disable the web event listeners and actions on window object
18
+ */
19
+ isNodeJS?: boolean;
20
+ /**
21
+ * Custom client initialization prop
22
+ */
23
+ client?: ClientType;
24
+ /**
25
+ * Custom cache initialization prop
26
+ */
27
+ cache?: <B extends BuilderInstance, C extends Cache>(builder: B) => C;
28
+ /**
29
+ * Custom app manager initialization prop
30
+ */
31
+ appManager?: <B extends BuilderInstance, A extends AppManager>(builder: B) => A;
32
+ /**
33
+ * Custom fetch dispatcher initialization prop
34
+ */
35
+ fetchDispatcher?: <B extends BuilderInstance, D extends Dispatcher>(builder: B) => D;
36
+ /**
37
+ * Custom submit dispatcher initialization prop
38
+ */
39
+ submitDispatcher?: <B extends BuilderInstance, D extends Dispatcher>(builder: B) => D;
40
+ };
41
+ export declare type BuilderInstance = Builder<any, any>;
42
+ export declare type BuilderErrorType = Record<string, any> | string;
43
+ export declare type RequestInterceptorCallback = (command: CommandInstance) => Promise<CommandInstance> | CommandInstance;
44
+ export declare type ResponseInterceptorCallback<Response = any, Error = any> = (response: ClientResponseType<Response, Error>, command: CommandInstance) => Promise<ClientResponseType<any, any>> | ClientResponseType<any, any>;
45
+ export declare type StringifyCallbackType = (queryParams: ClientQueryParamsType | string | NegativeTypes) => string;
@@ -0,0 +1,10 @@
1
+ import { ClientQueryParamsType, ClientResponseType, QueryStringifyOptions } from "../client";
2
+ import { CommandInstance } from "../command";
3
+ import { NegativeTypes } from "../types";
4
+ import { RequestInterceptorCallback, ResponseInterceptorCallback } from "./builder.types";
5
+ export declare const stringifyValue: (response: string | unknown) => string;
6
+ export declare const interceptRequest: (interceptors: RequestInterceptorCallback[], command: CommandInstance) => Promise<CommandInstance>;
7
+ export declare const interceptResponse: <GlobalErrorType>(interceptors: ResponseInterceptorCallback[], response: ClientResponseType<any, GlobalErrorType>, command: CommandInstance) => Promise<ClientResponseType<any, GlobalErrorType>>;
8
+ export declare const getClientHeaders: (command: CommandInstance) => HeadersInit;
9
+ export declare const getClientPayload: (data: unknown) => string | FormData;
10
+ export declare const stringifyQueryParams: (queryParams: ClientQueryParamsType | string | NegativeTypes, options?: QueryStringifyOptions) => string;
@@ -0,0 +1,4 @@
1
+ export * from "./builder";
2
+ export * from "./builder.utils";
3
+ export * from "./builder.types";
4
+ export * from "./builder.constants";
@@ -0,0 +1,76 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import EventEmitter from "events";
4
+ import { ClientResponseType } from "../client";
5
+ import { BuilderInstance } from "../builder";
6
+ import { CommandResponseDetails } from "../managers";
7
+ import { CacheOptionsType, CacheAsyncStorageType, CacheStorageType, getCacheEvents, CacheValueType } from "./";
8
+ import { CommandDump, CommandInstance } from "../command";
9
+ /**
10
+ * Cache class handles the data exchange with the dispatchers.
11
+ *
12
+ * @note
13
+ * Keys used to save the values are created dynamically on the Command class
14
+ *
15
+ */
16
+ export declare class Cache {
17
+ builder: BuilderInstance;
18
+ options?: CacheOptionsType;
19
+ emitter: EventEmitter;
20
+ events: ReturnType<typeof getCacheEvents>;
21
+ storage: CacheStorageType;
22
+ lazyStorage?: CacheAsyncStorageType;
23
+ clearKey: string;
24
+ garbageCollectors: Map<string, NodeJS.Timeout>;
25
+ private logger;
26
+ constructor(builder: BuilderInstance, options?: CacheOptionsType);
27
+ /**
28
+ * Set the cache data to the storage
29
+ * @param command
30
+ * @param response
31
+ * @param details
32
+ * @returns
33
+ */
34
+ set: <Response_1, Error_1>(command: CommandInstance | CommandDump<CommandInstance>, response: ClientResponseType<Response_1, Error_1>, details: CommandResponseDetails) => void;
35
+ /**
36
+ * Get particular record from storage by cacheKey. It will trigger lazyStorage to emit lazy load event for reading it's data.
37
+ * @param cacheKey
38
+ * @returns
39
+ */
40
+ get: <Response_1, Error_1>(cacheKey: string) => CacheValueType<Response_1, Error_1>;
41
+ /**
42
+ * Get sync storage keys, lazyStorage keys will not be included
43
+ * @returns
44
+ */
45
+ keys: () => string[];
46
+ /**
47
+ * Delete record from storages and trigger revalidation
48
+ * @param cacheKey
49
+ */
50
+ delete: (cacheKey: string) => void;
51
+ /**
52
+ * Revalidate cache by cacheKey or partial matching with RegExp
53
+ * @param cacheKey
54
+ */
55
+ revalidate: (cacheKey: string | RegExp) => Promise<void>;
56
+ /**
57
+ * Used to receive data from lazy storage
58
+ * @param cacheKey
59
+ */
60
+ getLazyResource: <Response_1, Error_1>(cacheKey: string) => Promise<CacheValueType<Response_1, Error_1>>;
61
+ /**
62
+ * Used to receive keys from sync storage and lazy storage
63
+ * @param cacheKey
64
+ */
65
+ getLazyKeys: () => Promise<string[]>;
66
+ /**
67
+ * Schedule garbage collection for given key
68
+ * @param cacheKey
69
+ * @returns
70
+ */
71
+ scheduleGarbageCollector: (cacheKey: string) => Promise<void>;
72
+ /**
73
+ * Clear cache storages
74
+ */
75
+ clear: () => Promise<void>;
76
+ }
@@ -0,0 +1,28 @@
1
+ import EventEmitter from "events";
2
+ import { CacheValueType } from "./";
3
+ export declare const getCacheEvents: (emitter: EventEmitter) => {
4
+ /**
5
+ * Set cache data
6
+ * @param cacheKey
7
+ * @param data
8
+ */
9
+ emitCacheData: <Response_1, Error_1>(cacheKey: string, data: CacheValueType<Response_1, Error_1>) => void;
10
+ /**
11
+ * Revalidate cache values event
12
+ */
13
+ emitRevalidation: (cacheKey: string) => void;
14
+ /**
15
+ * Cache data listener
16
+ * @param cacheKey
17
+ * @param callback
18
+ * @returns
19
+ */
20
+ onData: <Response_2, Error_2>(cacheKey: string, callback: (data: CacheValueType<Response_2, Error_2>) => void) => VoidFunction;
21
+ /**
22
+ * Cache invalidation listener
23
+ * @param cacheKey
24
+ * @param callback
25
+ * @returns
26
+ */
27
+ onRevalidate: (cacheKey: string, callback: () => void) => VoidFunction;
28
+ };
@@ -0,0 +1,49 @@
1
+ import { Cache } from "./";
2
+ import { ClientResponseType } from "../client";
3
+ import { CommandResponseDetails } from "../managers";
4
+ export declare type CacheOptionsType = {
5
+ /**
6
+ * Assign your custom sync storage
7
+ */
8
+ storage?: CacheStorageType;
9
+ /**
10
+ * Lazy loading from remote resources - possibly persistent
11
+ */
12
+ lazyStorage?: CacheAsyncStorageType;
13
+ /**
14
+ * Key to clear lazy storage data
15
+ */
16
+ clearKey?: string;
17
+ /**
18
+ * Initialization callback
19
+ */
20
+ onInitialization?: (cache: Cache) => void;
21
+ /**
22
+ * Callback for every change in the storage
23
+ */
24
+ onChange?: <Response = any, Error = any>(key: string, data: CacheValueType<Response, Error>) => void;
25
+ /**
26
+ * Callback for every delete in the storage
27
+ */
28
+ onDelete?: (key: string) => void;
29
+ };
30
+ export declare type CacheValueType<Response = any, Error = any> = {
31
+ data: ClientResponseType<Response, Error>;
32
+ details: CommandResponseDetails;
33
+ cacheTime: number;
34
+ clearKey: string;
35
+ };
36
+ export declare type CacheAsyncStorageType = {
37
+ set: <Response, Error>(key: string, data: CacheValueType<Response, Error>) => Promise<void>;
38
+ get: <Response, Error>(key: string) => Promise<CacheValueType<Response, Error> | undefined>;
39
+ keys: () => Promise<string[] | IterableIterator<string> | string[]>;
40
+ delete: (key: string) => Promise<void>;
41
+ };
42
+ export declare type CacheStorageType = {
43
+ set: <Response, Error>(key: string, data: CacheValueType<Response, Error>) => void;
44
+ get: <Response, Error>(key: string) => CacheValueType<Response, Error> | undefined;
45
+ keys: () => string[] | IterableIterator<string> | string[];
46
+ delete: (key: string) => void;
47
+ clear: () => void;
48
+ };
49
+ export declare type CacheInitialData = Record<string, CacheValueType>;
@@ -0,0 +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>;
4
+ export declare const getRevalidateEventKey: (key: string) => string;
5
+ export declare const getCacheKey: (key: string) => string;
6
+ export declare const getCacheIdKey: (key: string) => string;
@@ -0,0 +1,4 @@
1
+ export * from "./cache";
2
+ export * from "./cache.types";
3
+ export * from "./cache.utils";
4
+ export * from "./cache.events";
@@ -0,0 +1,25 @@
1
+ import { ClientResponseSuccessType, ClientResponseErrorType, ProgressRequestDataType } from "./";
2
+ import { CommandInstance } from "../command";
3
+ import { ExtractResponse, ExtractError } from "../types";
4
+ export declare const getClientBindings: (cmd: CommandInstance, requestId: string) => Promise<{
5
+ fullUrl: string;
6
+ headers: HeadersInit;
7
+ payload: string | FormData;
8
+ config: any;
9
+ getAbortController: () => AbortController;
10
+ getRequestStartTimestamp: () => number;
11
+ getResponseStartTimestamp: () => number;
12
+ createAbortListener: <T extends CommandInstance>(callback: () => void, resolve: (value: ClientResponseErrorType<ExtractError<T>>) => void) => () => void;
13
+ onBeforeRequest: () => void;
14
+ onRequestStart: (progress?: ProgressRequestDataType) => number;
15
+ onRequestProgress: (progress: ProgressRequestDataType) => number;
16
+ onRequestEnd: () => number;
17
+ onResponseStart: (progress?: ProgressRequestDataType) => number;
18
+ onResponseProgress: (progress: ProgressRequestDataType) => number;
19
+ onResponseEnd: () => number;
20
+ onSuccess: <T_1 extends CommandInstance>(responseData: unknown, status: number, resolve: (value: ClientResponseErrorType<ExtractError<T_1>>) => void) => Promise<ClientResponseSuccessType<ExtractResponse<T_1>>>;
21
+ onAbortError: <T_2 extends CommandInstance>(resolve: (value: ClientResponseErrorType<ExtractError<T_2>>) => void) => Promise<ClientResponseErrorType<ExtractError<T_2>>>;
22
+ onTimeoutError: <T_3 extends CommandInstance>(resolve: (value: ClientResponseErrorType<ExtractError<T_3>>) => void) => Promise<ClientResponseErrorType<ExtractError<T_3>>>;
23
+ onUnexpectedError: <T_4 extends CommandInstance>(resolve: (value: ClientResponseErrorType<ExtractError<T_4>>) => void) => Promise<ClientResponseErrorType<ExtractError<T_4>>>;
24
+ onError: <T_5 extends CommandInstance>(error: Error | ExtractError<T_5>, status: number, resolve: (value: ClientResponseErrorType<ExtractError<T_5>>) => void) => Promise<ClientResponseErrorType<ExtractError<T_5>>>;
25
+ }>;
@@ -0,0 +1 @@
1
+ export declare const defaultTimeout: number;
@@ -0,0 +1,2 @@
1
+ import { ClientType } from "./";
2
+ export declare const fetchClient: ClientType;
@@ -0,0 +1,57 @@
1
+ import { CommandInstance } from "../command";
2
+ export declare type ClientType = (command: CommandInstance, requestId: string) => Promise<ClientResponseType<any, any>>;
3
+ export declare type ClientDefaultOptionsType = Partial<XMLHttpRequest>;
4
+ export declare type ClientPayloadMappingCallback = (data: unknown) => string | FormData;
5
+ export declare type ClientResponseType<GenericDataType, GenericErrorType> = [
6
+ GenericDataType | null,
7
+ GenericErrorType | null,
8
+ number | null
9
+ ];
10
+ export declare type ClientResponseSuccessType<GenericDataType> = [GenericDataType, null, number | null];
11
+ export declare type ClientResponseErrorType<GenericErrorType> = [null, GenericErrorType, number | null];
12
+ export declare type ClientQueryParamValues = number | string | boolean | null | undefined;
13
+ export declare type ClientQueryParam = ClientQueryParamValues | Array<ClientQueryParamValues> | Record<string, ClientQueryParamValues>;
14
+ export declare type ClientQueryParamsType = Record<string, ClientQueryParam>;
15
+ export declare type ClientHeaderMappingCallback = <T extends CommandInstance>(command: T) => HeadersInit;
16
+ export declare type ClientHeadersProps = {
17
+ isFormData: boolean;
18
+ headers: HeadersInit | undefined;
19
+ };
20
+ export declare type QueryStringifyOptions = {
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 declare type ProgressRequestDataType = {
47
+ total?: number;
48
+ loaded?: number;
49
+ };
50
+ export declare type FetchProgressType = {
51
+ progress: number;
52
+ timeLeft: number | null;
53
+ sizeLeft: number;
54
+ total: number;
55
+ loaded: number;
56
+ startTimestamp: number;
57
+ };
@@ -0,0 +1,5 @@
1
+ import { CommandInstance } from "../command";
2
+ import { ExtractError } from "../types";
3
+ export declare const getErrorMessage: (errorCase?: "timeout" | "abort" | "deleted") => Error;
4
+ export declare const parseResponse: (response: string | unknown) => any;
5
+ export declare const parseErrorResponse: <T extends CommandInstance>(response: unknown) => ExtractError<T>;
@@ -0,0 +1,5 @@
1
+ export * from "./fetch.client";
2
+ export * from "./fetch.client.types";
3
+ export * from "./fetch.client.utils";
4
+ export * from "./fetch.client.bindings";
5
+ export * from "./fetch.client.constants";