@hyper-fetch/core 1.7.0 โ 2.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.
- package/README.md +3 -2
- package/dist/builder/builder.d.ts +17 -18
- package/dist/builder/builder.types.d.ts +14 -18
- package/dist/builder/builder.utils.d.ts +3 -3
- package/dist/cache/cache.d.ts +5 -5
- package/dist/cache/cache.events.d.ts +1 -1
- package/dist/cache/cache.types.d.ts +9 -9
- package/dist/cache/cache.utils.d.ts +2 -2
- package/dist/client/fetch.client.bindings.d.ts +5 -5
- package/dist/client/fetch.client.browser.d.ts +2 -0
- package/dist/client/fetch.client.d.ts +1 -1
- package/dist/client/fetch.client.server.d.ts +2 -0
- package/dist/client/fetch.client.types.d.ts +15 -15
- package/dist/client/fetch.client.utils.d.ts +5 -2
- package/dist/client/index.d.ts +1 -0
- package/dist/command/command.d.ts +11 -11
- package/dist/command/command.types.d.ts +27 -26
- package/dist/command/command.utils.d.ts +4 -4
- package/dist/dispatcher/dispatcher.d.ts +3 -3
- package/dist/dispatcher/dispatcher.events.d.ts +2 -2
- package/dist/dispatcher/dispatcher.types.d.ts +7 -7
- package/dist/dispatcher/dispatcher.utils.d.ts +3 -3
- package/dist/effect/fetch.effect.d.ts +4 -4
- package/dist/effect/fetch.effect.types.d.ts +7 -7
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +4 -4
- package/dist/index.d.ts +1 -0
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +4 -4
- package/dist/managers/app/app.manager.constants.d.ts +2 -2
- package/dist/managers/app/app.manager.d.ts +3 -4
- package/dist/managers/app/app.manager.types.d.ts +3 -4
- package/dist/managers/command/command.manager.d.ts +21 -21
- package/dist/managers/command/command.manager.events.d.ts +3 -3
- package/dist/managers/command/command.manager.types.d.ts +5 -5
- package/dist/managers/logger/logger.manager.d.ts +3 -3
- package/dist/managers/logger/logger.manager.types.d.ts +12 -12
- package/dist/managers/logger/logger.manager.utils.d.ts +1 -1
- package/dist/types/fetch.types.d.ts +16 -15
- package/dist/types/helpers.types.d.ts +5 -5
- package/dist/types/http.types.d.ts +1 -1
- package/package.json +5 -5
- package/release.config.js +0 -2
- package/src/builder/builder.ts +48 -50
- package/src/builder/builder.types.ts +1 -5
- package/src/cache/cache.ts +24 -17
- package/src/cache/cache.types.ts +1 -1
- package/src/client/fetch.client.bindings.ts +5 -5
- package/src/client/fetch.client.browser.ts +89 -0
- package/src/client/fetch.client.server.ts +105 -0
- package/src/client/fetch.client.ts +5 -94
- package/src/client/fetch.client.utils.ts +31 -0
- package/src/client/index.ts +1 -0
- package/src/command/command.ts +60 -18
- package/src/command/command.types.ts +14 -14
- package/src/index.ts +1 -0
- package/src/managers/app/app.manager.ts +7 -5
- package/src/managers/app/app.manager.types.ts +2 -4
- package/src/managers/logger/logger.manager.ts +1 -1
- package/src/types/fetch.types.ts +32 -12
package/README.md
CHANGED
|
@@ -50,7 +50,7 @@ particular `caching`, `queuing`, `persistence`, `offline first support`, `reques
|
|
|
50
50
|
|
|
51
51
|
๐ **Queueing** - [Read more](https://hyperfetch.bettertyped.com/guides/Advanced/Queueing)
|
|
52
52
|
|
|
53
|
-
๐ **Automatic caching** - [Read more](https://hyperfetch.bettertyped.com/docs/
|
|
53
|
+
๐ **Automatic caching** - [Read more](https://hyperfetch.bettertyped.com/docs/Core/Cache)
|
|
54
54
|
|
|
55
55
|
๐ช **Persistance** - [Read more](https://hyperfetch.bettertyped.com/guides/Advanced/Persistence)
|
|
56
56
|
|
|
@@ -58,7 +58,7 @@ particular `caching`, `queuing`, `persistence`, `offline first support`, `reques
|
|
|
58
58
|
|
|
59
59
|
๐ **Offline First** - [Read more](https://hyperfetch.bettertyped.com/guides/Advanced/Offline)
|
|
60
60
|
|
|
61
|
-
๐ก **Built-in client** - [Read more](https://hyperfetch.bettertyped.com/docs/
|
|
61
|
+
๐ก **Built-in client** - [Read more](https://hyperfetch.bettertyped.com/docs/Core/Client)
|
|
62
62
|
|
|
63
63
|
๐งช **Easy to test** - [Read more](https://hyperfetch.bettertyped.com/docs/Getting%20Started/Testing)
|
|
64
64
|
|
|
@@ -76,4 +76,5 @@ particular `caching`, `queuing`, `persistence`, `offline first support`, `reques
|
|
|
76
76
|
|
|
77
77
|
## Other Packages
|
|
78
78
|
|
|
79
|
+
- #### [Hyper Fetch Sockets](https://github.com/BetterTyped/hyper-fetch/tree/main/packages/sockets)
|
|
79
80
|
- #### [React Hyper Fetch](https://github.com/BetterTyped/hyper-fetch/tree/main/packages/react)
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { ClientType, ClientDefaultOptionsType, ClientResponseType, ClientQueryParamsType, QueryStringifyOptions, ClientHeaderMappingCallback, ClientPayloadMappingCallback } from "
|
|
2
|
-
import { BuilderConfig, BuilderInstance, BuilderErrorType, StringifyCallbackType, RequestInterceptorCallback, ResponseInterceptorCallback } from "
|
|
3
|
-
import { Cache } from "
|
|
4
|
-
import { Dispatcher } from "
|
|
5
|
-
import { FetchEffectInstance } from "
|
|
6
|
-
import { Command, CommandConfig, CommandInstance } from "
|
|
7
|
-
import { AppManager, CommandManager, LoggerManager, SeverityType } from "
|
|
1
|
+
import { ClientType, ClientDefaultOptionsType, ClientResponseType, ClientQueryParamsType, QueryStringifyOptions, ClientHeaderMappingCallback, ClientPayloadMappingCallback } from "client";
|
|
2
|
+
import { BuilderConfig, BuilderInstance, BuilderErrorType, StringifyCallbackType, RequestInterceptorCallback, ResponseInterceptorCallback } from "builder";
|
|
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
8
|
/**
|
|
9
9
|
* **Builder** is a class that allows you to configure the connection with the server and then use it to create
|
|
10
10
|
* commands which, when called using the appropriate method, will cause the server to be queried for the endpoint and
|
|
@@ -13,8 +13,7 @@ import { AppManager, CommandManager, LoggerManager, SeverityType } from "../mana
|
|
|
13
13
|
*/
|
|
14
14
|
export declare class Builder<GlobalErrorType extends BuilderErrorType = Error, RequestConfigType = ClientDefaultOptionsType> {
|
|
15
15
|
options: BuilderConfig;
|
|
16
|
-
readonly
|
|
17
|
-
readonly isNodeJS: boolean;
|
|
16
|
+
readonly url: string;
|
|
18
17
|
debug: boolean;
|
|
19
18
|
__onErrorCallbacks: ResponseInterceptorCallback[];
|
|
20
19
|
__onSuccessCallbacks: ResponseInterceptorCallback[];
|
|
@@ -44,7 +43,7 @@ export declare class Builder<GlobalErrorType extends BuilderErrorType = Error, R
|
|
|
44
43
|
* Method to get request data and transform them to the required format. It handles FormData and JSON by default.
|
|
45
44
|
*/
|
|
46
45
|
payloadMapper: ClientPayloadMappingCallback;
|
|
47
|
-
logger: import("
|
|
46
|
+
logger: import("managers").LoggerType;
|
|
48
47
|
constructor(options: BuilderConfig);
|
|
49
48
|
/**
|
|
50
49
|
* This method allows to configure global defaults for the command configuration like method, auth, deduplication etc.
|
|
@@ -111,14 +110,6 @@ export declare class Builder<GlobalErrorType extends BuilderErrorType = Error, R
|
|
|
111
110
|
* Remove effects from builder
|
|
112
111
|
*/
|
|
113
112
|
removeEffect: (effect: FetchEffectInstance | string) => this;
|
|
114
|
-
/**
|
|
115
|
-
* Create commands based on the builder setup
|
|
116
|
-
*/
|
|
117
|
-
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>;
|
|
118
|
-
/**
|
|
119
|
-
* Clears the builder instance and remove all listeners on it's dependencies
|
|
120
|
-
*/
|
|
121
|
-
clear: () => void;
|
|
122
113
|
/**
|
|
123
114
|
* Helper used by http client to apply the modifications on response error
|
|
124
115
|
*/
|
|
@@ -139,4 +130,12 @@ export declare class Builder<GlobalErrorType extends BuilderErrorType = Error, R
|
|
|
139
130
|
* Private helper to run async response processing
|
|
140
131
|
*/
|
|
141
132
|
__modifyResponse: (response: ClientResponseType<any, GlobalErrorType>, command: CommandInstance) => Promise<ClientResponseType<any, GlobalErrorType>>;
|
|
133
|
+
/**
|
|
134
|
+
* Clears the builder instance and remove all listeners on it's dependencies
|
|
135
|
+
*/
|
|
136
|
+
clear: () => void;
|
|
137
|
+
/**
|
|
138
|
+
* Create commands based on the builder setup
|
|
139
|
+
*/
|
|
140
|
+
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>;
|
|
142
141
|
}
|
|
@@ -1,22 +1,18 @@
|
|
|
1
|
-
import { Cache } from "
|
|
2
|
-
import { CommandInstance } from "
|
|
3
|
-
import { Dispatcher } from "
|
|
4
|
-
import { ClientResponseType, ClientType, ClientQueryParamsType } from "
|
|
5
|
-
import { Builder } from "
|
|
6
|
-
import { AppManager } from "
|
|
7
|
-
import { NegativeTypes } from "
|
|
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 "builder";
|
|
6
|
+
import { AppManager } from "managers";
|
|
7
|
+
import { NegativeTypes } from "types";
|
|
8
8
|
/**
|
|
9
9
|
* Configuration setup for the builder
|
|
10
10
|
*/
|
|
11
|
-
export
|
|
11
|
+
export type BuilderConfig = {
|
|
12
12
|
/**
|
|
13
13
|
* Url to your server
|
|
14
14
|
*/
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Disable the web event listeners and actions on window object
|
|
18
|
-
*/
|
|
19
|
-
isNodeJS?: boolean;
|
|
15
|
+
url: string;
|
|
20
16
|
/**
|
|
21
17
|
* Custom client initialization prop
|
|
22
18
|
*/
|
|
@@ -38,8 +34,8 @@ export declare type BuilderConfig = {
|
|
|
38
34
|
*/
|
|
39
35
|
submitDispatcher?: <B extends BuilderInstance, D extends Dispatcher>(builder: B) => D;
|
|
40
36
|
};
|
|
41
|
-
export
|
|
42
|
-
export
|
|
43
|
-
export
|
|
44
|
-
export
|
|
45
|
-
export
|
|
37
|
+
export type BuilderInstance = Builder<any, any>;
|
|
38
|
+
export type BuilderErrorType = Record<string, any> | string;
|
|
39
|
+
export type RequestInterceptorCallback = (command: CommandInstance) => Promise<CommandInstance> | CommandInstance;
|
|
40
|
+
export type ResponseInterceptorCallback<Response = any, Error = any> = (response: ClientResponseType<Response, Error>, command: CommandInstance) => Promise<ClientResponseType<any, any>> | ClientResponseType<any, any>;
|
|
41
|
+
export type StringifyCallbackType = (queryParams: ClientQueryParamsType | string | NegativeTypes) => string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ClientQueryParamsType, ClientResponseType, QueryStringifyOptions } from "
|
|
2
|
-
import { CommandInstance } from "
|
|
3
|
-
import { NegativeTypes } from "
|
|
1
|
+
import { ClientQueryParamsType, ClientResponseType, QueryStringifyOptions } from "client";
|
|
2
|
+
import { CommandInstance } from "command";
|
|
3
|
+
import { NegativeTypes } from "types";
|
|
4
4
|
import { RequestInterceptorCallback, ResponseInterceptorCallback } from "./builder.types";
|
|
5
5
|
export declare const stringifyValue: (response: string | unknown) => string;
|
|
6
6
|
export declare const interceptRequest: (interceptors: RequestInterceptorCallback[], command: CommandInstance) => Promise<CommandInstance>;
|
package/dist/cache/cache.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
import EventEmitter from "events";
|
|
4
|
-
import { ClientResponseType } from "
|
|
5
|
-
import { BuilderInstance } from "
|
|
6
|
-
import { CommandResponseDetails } from "
|
|
7
|
-
import { CacheOptionsType, CacheAsyncStorageType, CacheStorageType, getCacheEvents, CacheValueType } from "
|
|
8
|
-
import { CommandDump, CommandInstance } from "
|
|
4
|
+
import { ClientResponseType } from "client";
|
|
5
|
+
import { BuilderInstance } from "builder";
|
|
6
|
+
import { CommandResponseDetails } from "managers";
|
|
7
|
+
import { CacheOptionsType, CacheAsyncStorageType, CacheStorageType, getCacheEvents, CacheValueType } from "cache";
|
|
8
|
+
import { CommandDump, CommandInstance } from "command";
|
|
9
9
|
/**
|
|
10
10
|
* Cache class handles the data exchange with the dispatchers.
|
|
11
11
|
*
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Cache } from "
|
|
2
|
-
import { ClientResponseType } from "
|
|
3
|
-
import { CommandResponseDetails } from "
|
|
4
|
-
export
|
|
1
|
+
import { Cache } from "cache";
|
|
2
|
+
import { ClientResponseType } from "client";
|
|
3
|
+
import { CommandResponseDetails } from "managers";
|
|
4
|
+
export type CacheOptionsType = {
|
|
5
5
|
/**
|
|
6
6
|
* Assign your custom sync storage
|
|
7
7
|
*/
|
|
@@ -27,24 +27,24 @@ export declare type CacheOptionsType = {
|
|
|
27
27
|
*/
|
|
28
28
|
onDelete?: (key: string) => void;
|
|
29
29
|
};
|
|
30
|
-
export
|
|
30
|
+
export type CacheValueType<Response = any, Error = any> = {
|
|
31
31
|
data: ClientResponseType<Response, Error>;
|
|
32
32
|
details: CommandResponseDetails;
|
|
33
33
|
cacheTime: number;
|
|
34
34
|
clearKey: string;
|
|
35
|
-
garbageCollection:
|
|
35
|
+
garbageCollection: number;
|
|
36
36
|
};
|
|
37
|
-
export
|
|
37
|
+
export type CacheAsyncStorageType = {
|
|
38
38
|
set: <Response, Error>(key: string, data: CacheValueType<Response, Error>) => Promise<void>;
|
|
39
39
|
get: <Response, Error>(key: string) => Promise<CacheValueType<Response, Error> | undefined>;
|
|
40
40
|
keys: () => Promise<string[] | IterableIterator<string> | string[]>;
|
|
41
41
|
delete: (key: string) => Promise<void>;
|
|
42
42
|
};
|
|
43
|
-
export
|
|
43
|
+
export type CacheStorageType = {
|
|
44
44
|
set: <Response, Error>(key: string, data: CacheValueType<Response, Error>) => void;
|
|
45
45
|
get: <Response, Error>(key: string) => CacheValueType<Response, Error> | undefined;
|
|
46
46
|
keys: () => string[] | IterableIterator<string> | string[];
|
|
47
47
|
delete: (key: string) => void;
|
|
48
48
|
clear: () => void;
|
|
49
49
|
};
|
|
50
|
-
export
|
|
50
|
+
export type CacheInitialData = Record<string, CacheValueType>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { CommandInstance } from "
|
|
2
|
-
import { ExtractClientReturnType } from "
|
|
1
|
+
import { CommandInstance } from "command";
|
|
2
|
+
import { ExtractClientReturnType } from "types";
|
|
3
3
|
export declare const getCacheData: <T extends CommandInstance>(previousResponse: ExtractClientReturnType<T>, response: ExtractClientReturnType<T>) => ExtractClientReturnType<T>;
|
|
4
4
|
export declare const getRevalidateEventKey: (key: string) => string;
|
|
5
5
|
export declare const getCacheKey: (key: string) => string;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { ClientResponseSuccessType, ClientResponseErrorType, ProgressRequestDataType } from "
|
|
2
|
-
import { CommandInstance } from "
|
|
3
|
-
import { ExtractResponse, ExtractError } from "
|
|
4
|
-
export declare const getClientBindings: (cmd: CommandInstance, requestId: string) => Promise<{
|
|
1
|
+
import { ClientResponseSuccessType, ClientResponseErrorType, ProgressRequestDataType } from "client";
|
|
2
|
+
import { CommandInstance } from "command";
|
|
3
|
+
import { ExtractResponse, ExtractError } from "types";
|
|
4
|
+
export declare const getClientBindings: <ConfigType = any>(cmd: CommandInstance, requestId: string) => Promise<{
|
|
5
5
|
fullUrl: string;
|
|
6
6
|
headers: HeadersInit;
|
|
7
7
|
payload: string | FormData;
|
|
8
|
-
config:
|
|
8
|
+
config: ConfigType;
|
|
9
9
|
getAbortController: () => AbortController;
|
|
10
10
|
getRequestStartTimestamp: () => number;
|
|
11
11
|
getResponseStartTimestamp: () => number;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { ClientType } from "
|
|
1
|
+
import { ClientType } from "client";
|
|
2
2
|
export declare const fetchClient: ClientType;
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { CommandInstance } from "
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
1
|
+
import { CommandInstance } from "command";
|
|
2
|
+
export type ClientType = (command: CommandInstance, requestId: string) => Promise<ClientResponseType<any, any>>;
|
|
3
|
+
export type ClientDefaultOptionsType = Partial<XMLHttpRequest>;
|
|
4
|
+
export type ClientPayloadMappingCallback = (data: unknown) => string | FormData;
|
|
5
|
+
export type ClientResponseType<GenericDataType, GenericErrorType> = [
|
|
6
6
|
GenericDataType | null,
|
|
7
7
|
GenericErrorType | null,
|
|
8
8
|
number | null
|
|
9
9
|
];
|
|
10
|
-
export
|
|
11
|
-
export
|
|
12
|
-
export
|
|
13
|
-
export
|
|
14
|
-
export
|
|
15
|
-
export
|
|
16
|
-
export
|
|
10
|
+
export type ClientResponseSuccessType<GenericDataType> = [GenericDataType, null, number | null];
|
|
11
|
+
export type ClientResponseErrorType<GenericErrorType> = [null, GenericErrorType, number | null];
|
|
12
|
+
export type ClientQueryParamValues = number | string | boolean | null | undefined;
|
|
13
|
+
export type ClientQueryParam = ClientQueryParamValues | Array<ClientQueryParamValues> | Record<string, ClientQueryParamValues>;
|
|
14
|
+
export type ClientQueryParamsType = Record<string, ClientQueryParam>;
|
|
15
|
+
export type ClientHeaderMappingCallback = <T extends CommandInstance>(command: T) => HeadersInit;
|
|
16
|
+
export type ClientHeadersProps = {
|
|
17
17
|
isFormData: boolean;
|
|
18
18
|
headers: HeadersInit | undefined;
|
|
19
19
|
};
|
|
20
|
-
export
|
|
20
|
+
export type QueryStringifyOptions = {
|
|
21
21
|
/**
|
|
22
22
|
* Strict URI encoding
|
|
23
23
|
*/
|
|
@@ -43,11 +43,11 @@ export declare type QueryStringifyOptions = {
|
|
|
43
43
|
*/
|
|
44
44
|
skipEmptyString?: boolean;
|
|
45
45
|
};
|
|
46
|
-
export
|
|
46
|
+
export type ProgressRequestDataType = {
|
|
47
47
|
total?: number;
|
|
48
48
|
loaded?: number;
|
|
49
49
|
};
|
|
50
|
-
export
|
|
50
|
+
export type FetchProgressType = {
|
|
51
51
|
progress: number;
|
|
52
52
|
timeLeft: number | null;
|
|
53
53
|
sizeLeft: number;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import { CommandInstance } from "
|
|
2
|
-
import { ExtractError } from "
|
|
1
|
+
import { CommandInstance } from "command";
|
|
2
|
+
import { ExtractError } from "types";
|
|
3
3
|
export declare const getErrorMessage: (errorCase?: "timeout" | "abort" | "deleted") => Error;
|
|
4
4
|
export declare const parseResponse: (response: string | unknown) => any;
|
|
5
5
|
export declare const parseErrorResponse: <T extends CommandInstance>(response: unknown) => ExtractError<T>;
|
|
6
|
+
export declare const getUploadSize: (payload: FormData | string) => number;
|
|
7
|
+
export declare const fileToBuffer: (file: File | Blob) => Promise<Uint8Array>;
|
|
8
|
+
export declare const getStreamPayload: (payload: FormData | string | null) => string | Promise<(string | Uint8Array)[]>;
|
package/dist/client/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { FetchMethodType, CommandData, CommandDump, CommandConfig, ExtractRouteParams, CommandCurrentType } from "
|
|
2
|
-
import { Builder } from "
|
|
3
|
-
import { ClientQueryParamsType } from "
|
|
4
|
-
import { HttpMethodsType, NegativeTypes } from "
|
|
1
|
+
import { FetchMethodType, CommandData, CommandDump, CommandConfig, ExtractRouteParams, CommandCurrentType, CommandMapperType } from "command";
|
|
2
|
+
import { Builder } from "builder";
|
|
3
|
+
import { ClientQueryParamsType } from "client";
|
|
4
|
+
import { HttpMethodsType, NegativeTypes } from "types";
|
|
5
5
|
/**
|
|
6
6
|
* Fetch command it is designed to prepare the necessary setup to execute the request to the server.
|
|
7
7
|
* We can setup basic options for example endpoint, method, headers and advanced settings like cache, invalidation patterns, concurrency, retries and much, much more.
|
|
@@ -19,7 +19,7 @@ EndpointType extends string, ClientOptions, HasData extends true | false = false
|
|
|
19
19
|
readonly builder: Builder<GlobalErrorType, ClientOptions>;
|
|
20
20
|
readonly commandOptions: CommandConfig<EndpointType, ClientOptions>;
|
|
21
21
|
readonly commandDump?: CommandCurrentType<ResponseType, RequestDataType, QueryParamsType, GlobalErrorType | LocalErrorType, EndpointType, ClientOptions, MappedData> | undefined;
|
|
22
|
-
readonly dataMapper?:
|
|
22
|
+
readonly dataMapper?: CommandMapperType<RequestDataType, MappedData>;
|
|
23
23
|
endpoint: EndpointType;
|
|
24
24
|
headers?: HeadersInit;
|
|
25
25
|
auth: boolean;
|
|
@@ -31,7 +31,7 @@ EndpointType extends string, ClientOptions, HasData extends true | false = false
|
|
|
31
31
|
cancelable: boolean;
|
|
32
32
|
retry: number;
|
|
33
33
|
retryTime: number;
|
|
34
|
-
garbageCollection:
|
|
34
|
+
garbageCollection: number;
|
|
35
35
|
cache: boolean;
|
|
36
36
|
cacheTime: number;
|
|
37
37
|
queued: boolean;
|
|
@@ -47,11 +47,11 @@ EndpointType extends string, ClientOptions, HasData extends true | false = false
|
|
|
47
47
|
private updatedCacheKey;
|
|
48
48
|
private updatedQueueKey;
|
|
49
49
|
private updatedEffectKey;
|
|
50
|
-
constructor(builder: Builder<GlobalErrorType, ClientOptions>, commandOptions: CommandConfig<EndpointType, ClientOptions>, commandDump?: CommandCurrentType<ResponseType, RequestDataType, QueryParamsType, GlobalErrorType | LocalErrorType, EndpointType, ClientOptions, MappedData> | undefined, dataMapper?:
|
|
50
|
+
constructor(builder: Builder<GlobalErrorType, ClientOptions>, commandOptions: CommandConfig<EndpointType, ClientOptions>, commandDump?: CommandCurrentType<ResponseType, RequestDataType, QueryParamsType, GlobalErrorType | LocalErrorType, EndpointType, ClientOptions, MappedData> | undefined, dataMapper?: CommandMapperType<RequestDataType, MappedData>);
|
|
51
51
|
setHeaders: (headers: HeadersInit) => Command<ResponseType, RequestDataType, QueryParamsType, GlobalErrorType, LocalErrorType, EndpointType, ClientOptions, HasData, HasParams, HasQuery, MappedData>;
|
|
52
52
|
setAuth: (auth: boolean) => Command<ResponseType, RequestDataType, QueryParamsType, GlobalErrorType, LocalErrorType, EndpointType, ClientOptions, HasData, HasParams, HasQuery, MappedData>;
|
|
53
|
-
setParams: (params:
|
|
54
|
-
setData: (data:
|
|
53
|
+
setParams: <P extends ExtractRouteParams<EndpointType>>(params: P) => Command<ResponseType, RequestDataType, QueryParamsType, GlobalErrorType, LocalErrorType, EndpointType, ClientOptions, HasData, P extends null ? false : true, HasQuery, MappedData>;
|
|
54
|
+
setData: <D extends RequestDataType>(data: D) => Command<ResponseType, RequestDataType, QueryParamsType, GlobalErrorType, LocalErrorType, EndpointType, ClientOptions, D extends null ? false : true, HasParams, HasQuery, MappedData>;
|
|
55
55
|
setQueryParams: (queryParams: QueryParamsType) => Command<ResponseType, RequestDataType, QueryParamsType, GlobalErrorType, LocalErrorType, EndpointType, ClientOptions, HasData, HasParams, true, MappedData>;
|
|
56
56
|
setOptions: (options: ClientOptions) => Command<ResponseType, RequestDataType, QueryParamsType, GlobalErrorType, LocalErrorType, EndpointType, ClientOptions, HasData, HasParams, true, MappedData>;
|
|
57
57
|
setCancelable: (cancelable: boolean) => Command<ResponseType, RequestDataType, QueryParamsType, GlobalErrorType, LocalErrorType, EndpointType, ClientOptions, HasData, HasParams, HasQuery, MappedData>;
|
|
@@ -69,10 +69,10 @@ EndpointType extends string, ClientOptions, HasData extends true | false = false
|
|
|
69
69
|
setDeduplicateTime: (deduplicateTime: number) => Command<ResponseType, RequestDataType, QueryParamsType, GlobalErrorType, LocalErrorType, EndpointType, ClientOptions, HasData, HasParams, HasQuery, MappedData>;
|
|
70
70
|
setUsed: (used: boolean) => Command<ResponseType, RequestDataType, QueryParamsType, GlobalErrorType, LocalErrorType, EndpointType, ClientOptions, HasData, HasParams, HasQuery, MappedData>;
|
|
71
71
|
setOffline: (offline: boolean) => Command<ResponseType, RequestDataType, QueryParamsType, GlobalErrorType, LocalErrorType, EndpointType, ClientOptions, HasData, HasParams, HasQuery, MappedData>;
|
|
72
|
-
setDataMapper: <DataMapper
|
|
72
|
+
setDataMapper: <DataMapper extends (data: RequestDataType) => any>(mapper: DataMapper) => Command<ResponseType, RequestDataType, QueryParamsType, GlobalErrorType, LocalErrorType, EndpointType, ClientOptions, HasData, HasParams, HasQuery, MappedData>;
|
|
73
73
|
private paramsMapper;
|
|
74
74
|
dump(): CommandDump<Command<ResponseType, RequestDataType, QueryParamsType, GlobalErrorType, LocalErrorType, EndpointType, ClientOptions, HasData, HasParams, HasQuery, MappedData>, ClientOptions, QueryParamsType>;
|
|
75
|
-
clone<D extends true | false = HasData, P extends true | false = HasParams, Q extends true | false = HasQuery,
|
|
75
|
+
clone<D extends true | false = HasData, P extends true | false = HasParams, Q extends true | false = HasQuery, NewMappedData = MappedData>(options?: CommandCurrentType<ResponseType, RequestDataType, QueryParamsType, GlobalErrorType | LocalErrorType, EndpointType, ClientOptions, NewMappedData>, mapper?: CommandMapperType<RequestDataType, NewMappedData>): Command<ResponseType, RequestDataType, QueryParamsType, GlobalErrorType, LocalErrorType, EndpointType, ClientOptions, D, P, Q, NewMappedData>;
|
|
76
76
|
abort: () => Command<ResponseType, RequestDataType, QueryParamsType, GlobalErrorType, LocalErrorType, EndpointType, ClientOptions, HasData, HasParams, HasQuery, MappedData>;
|
|
77
77
|
/**
|
|
78
78
|
* Method to use the command WITHOUT adding it to cache and queues. This mean it will make simple request without queue side effects.
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { NullableKeys, NegativeTypes, ExtractParams, ExtractRequestData, HttpMethodsType, ExtractQueryParams, ExtractClientOptions, ExtractEndpoint, ExtractHasData, ExtractHasParams, ExtractHasQueryParams, ExtractError, ExtractResponse } from "
|
|
2
|
-
import { Command } from "
|
|
3
|
-
import { ClientResponseType, ClientQueryParamsType, FetchProgressType } from "
|
|
4
|
-
import { CommandEventDetails, CommandResponseDetails } from "
|
|
5
|
-
export
|
|
1
|
+
import { NullableKeys, NegativeTypes, ExtractParams, ExtractRequestData, HttpMethodsType, ExtractQueryParams, ExtractClientOptions, ExtractEndpoint, ExtractHasData, ExtractHasParams, ExtractHasQueryParams, ExtractError, ExtractResponse } from "types";
|
|
2
|
+
import { Command } from "command";
|
|
3
|
+
import { ClientResponseType, ClientQueryParamsType, FetchProgressType } from "client";
|
|
4
|
+
import { CommandEventDetails, CommandResponseDetails } from "managers";
|
|
5
|
+
export type ClientProgressEvent = {
|
|
6
6
|
total: number;
|
|
7
7
|
loaded: number;
|
|
8
8
|
};
|
|
9
|
-
export
|
|
9
|
+
export type ClientProgressResponse = {
|
|
10
10
|
progress: number;
|
|
11
11
|
timeLeft: number;
|
|
12
12
|
sizeLeft: number;
|
|
@@ -14,7 +14,7 @@ export declare type ClientProgressResponse = {
|
|
|
14
14
|
/**
|
|
15
15
|
* Dump of the command used to later recreate it
|
|
16
16
|
*/
|
|
17
|
-
export
|
|
17
|
+
export type CommandDump<Command extends CommandInstance, ClientOptions = unknown, QueryParamsType = ClientQueryParamsType, Params = ExtractParams<Command>> = {
|
|
18
18
|
commandOptions: CommandConfig<string, ClientOptions | ExtractClientOptions<Command>>;
|
|
19
19
|
endpoint: string;
|
|
20
20
|
method: HttpMethodsType;
|
|
@@ -23,7 +23,7 @@ export declare type CommandDump<Command extends CommandInstance, ClientOptions =
|
|
|
23
23
|
cancelable: boolean;
|
|
24
24
|
retry: number;
|
|
25
25
|
retryTime: number;
|
|
26
|
-
garbageCollection:
|
|
26
|
+
garbageCollection: number;
|
|
27
27
|
cache: boolean;
|
|
28
28
|
cacheTime: number;
|
|
29
29
|
queued: boolean;
|
|
@@ -49,7 +49,7 @@ export declare type CommandDump<Command extends CommandInstance, ClientOptions =
|
|
|
49
49
|
/**
|
|
50
50
|
* Configuration options for command creation
|
|
51
51
|
*/
|
|
52
|
-
export
|
|
52
|
+
export type CommandConfig<GenericEndpoint extends string, ClientOptions> = {
|
|
53
53
|
/**
|
|
54
54
|
* Determine the endpoint for command request
|
|
55
55
|
*/
|
|
@@ -81,7 +81,7 @@ export declare type CommandConfig<GenericEndpoint extends string, ClientOptions>
|
|
|
81
81
|
/**
|
|
82
82
|
* Should we trigger garbage collection or leave data in memory
|
|
83
83
|
*/
|
|
84
|
-
garbageCollection?:
|
|
84
|
+
garbageCollection?: number;
|
|
85
85
|
/**
|
|
86
86
|
* Should we save the response to cache
|
|
87
87
|
*/
|
|
@@ -135,8 +135,9 @@ export declare type CommandConfig<GenericEndpoint extends string, ClientOptions>
|
|
|
135
135
|
*/
|
|
136
136
|
deduplicateTime?: number;
|
|
137
137
|
};
|
|
138
|
-
export
|
|
139
|
-
export
|
|
138
|
+
export type CommandMapperType<RequestDataType, MappedData> = (data: RequestDataType) => MappedData;
|
|
139
|
+
export type CommandData<RequestDataType, MappedData> = (MappedData extends never ? RequestDataType : MappedData) | NegativeTypes;
|
|
140
|
+
export type CommandCurrentType<ResponseType, RequestDataType, QueryParamsType, ErrorType, GenericEndpoint extends string, ClientOptions, MappedData> = {
|
|
140
141
|
used?: boolean;
|
|
141
142
|
params?: ExtractRouteParams<GenericEndpoint> | NegativeTypes;
|
|
142
143
|
queryParams?: QueryParamsType | NegativeTypes;
|
|
@@ -148,18 +149,18 @@ export declare type CommandCurrentType<ResponseType, RequestDataType, QueryParam
|
|
|
148
149
|
updatedQueueKey?: boolean;
|
|
149
150
|
updatedEffectKey?: boolean;
|
|
150
151
|
} & Partial<NullableKeys<CommandConfig<GenericEndpoint, ClientOptions>>>;
|
|
151
|
-
export
|
|
152
|
-
export
|
|
153
|
-
export
|
|
152
|
+
export type ParamType = string | number;
|
|
153
|
+
export type ParamsType = Record<string, ParamType>;
|
|
154
|
+
export type ExtractRouteParams<T extends string> = string extends T ? NegativeTypes : T extends `${string}:${infer Param}/${infer Rest}` ? {
|
|
154
155
|
[k in Param | keyof ExtractRouteParams<Rest>]: ParamType;
|
|
155
156
|
} : T extends `${string}:${infer Param}` ? {
|
|
156
157
|
[k in Param]: ParamType;
|
|
157
158
|
} : NegativeTypes;
|
|
158
|
-
export
|
|
159
|
+
export type FetchOptionsType<ClientOptions> = Omit<Partial<CommandConfig<string, ClientOptions>>, "endpoint" | "method">;
|
|
159
160
|
/**
|
|
160
161
|
* It will check if the query params are already set
|
|
161
162
|
*/
|
|
162
|
-
export
|
|
163
|
+
export type FetchQueryParamsType<QueryParamsType extends ClientQueryParamsType | string, HasQuery extends true | false = false> = HasQuery extends true ? {
|
|
163
164
|
queryParams?: NegativeTypes;
|
|
164
165
|
} : {
|
|
165
166
|
queryParams?: QueryParamsType | string;
|
|
@@ -167,28 +168,28 @@ export declare type FetchQueryParamsType<QueryParamsType, HasQuery extends true
|
|
|
167
168
|
/**
|
|
168
169
|
* If the command endpoint parameters are not filled it will throw an error
|
|
169
170
|
*/
|
|
170
|
-
export
|
|
171
|
+
export type FetchParamsType<EndpointType extends string, HasParams extends true | false> = ExtractRouteParams<EndpointType> extends NegativeTypes ? {
|
|
171
172
|
params?: NegativeTypes;
|
|
172
173
|
} : true extends HasParams ? {
|
|
173
174
|
params?: NegativeTypes;
|
|
174
175
|
} : {
|
|
175
|
-
params: ExtractRouteParams<EndpointType
|
|
176
|
+
params: NonNullable<ExtractRouteParams<EndpointType>>;
|
|
176
177
|
};
|
|
177
178
|
/**
|
|
178
179
|
* If the command data is not filled it will throw an error
|
|
179
180
|
*/
|
|
180
|
-
export
|
|
181
|
+
export type FetchRequestDataType<RequestDataType, HasData extends true | false> = RequestDataType extends NegativeTypes ? {
|
|
181
182
|
data?: NegativeTypes;
|
|
182
183
|
} : HasData extends true ? {
|
|
183
184
|
data?: NegativeTypes;
|
|
184
185
|
} : {
|
|
185
|
-
data: RequestDataType
|
|
186
|
+
data: NonNullable<RequestDataType>;
|
|
186
187
|
};
|
|
187
|
-
export
|
|
188
|
+
export type CommandQueueOptions = {
|
|
188
189
|
dispatcherType?: "auto" | "fetch" | "submit";
|
|
189
190
|
};
|
|
190
|
-
export
|
|
191
|
-
export
|
|
191
|
+
export type FetchType<Command extends CommandInstance> = FetchQueryParamsType<ExtractQueryParams<Command>, ExtractHasQueryParams<Command>> & FetchParamsType<ExtractEndpoint<Command>, ExtractHasParams<Command>> & FetchRequestDataType<ExtractRequestData<Command>, ExtractHasData<Command>> & Omit<FetchOptionsType<ExtractClientOptions<Command>>, "params" | "data"> & FetchSendActionsType<Command> & CommandQueueOptions;
|
|
192
|
+
export type FetchSendActionsType<Command extends CommandInstance> = {
|
|
192
193
|
onSettle?: (requestId: string, command: Command) => void;
|
|
193
194
|
onRequestStart?: (details: CommandEventDetails<Command>) => void;
|
|
194
195
|
onResponseStart?: (details: CommandEventDetails<Command>) => void;
|
|
@@ -197,5 +198,5 @@ export declare type FetchSendActionsType<Command extends CommandInstance> = {
|
|
|
197
198
|
onResponse?: (response: ClientResponseType<ExtractResponse<Command>, ExtractError<Command>>, details: CommandResponseDetails) => void;
|
|
198
199
|
onRemove?: (details: CommandEventDetails<Command>) => void;
|
|
199
200
|
};
|
|
200
|
-
export
|
|
201
|
-
export
|
|
201
|
+
export type FetchMethodType<Command extends CommandInstance> = FetchType<Command>["data"] extends NegativeTypes ? FetchType<Command>["params"] extends NegativeTypes ? (options?: FetchType<Command>) => Promise<ClientResponseType<ExtractResponse<Command>, ExtractError<Command>>> : (options: FetchType<Command>) => Promise<ClientResponseType<ExtractResponse<Command>, ExtractError<Command>>> : (options: FetchType<Command>) => Promise<ClientResponseType<ExtractResponse<Command>, ExtractError<Command>>>;
|
|
202
|
+
export type CommandInstance = Command<any, any, any, any, any, any, any, any, any, any, any>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { FetchProgressType, ClientResponseType } from "
|
|
2
|
-
import { ClientProgressEvent, CommandInstance, CommandDump, FetchType } from "
|
|
3
|
-
import { Dispatcher } from "
|
|
4
|
-
import { ExtractError, ExtractResponse } from "
|
|
1
|
+
import { FetchProgressType, ClientResponseType } from "client";
|
|
2
|
+
import { ClientProgressEvent, CommandInstance, CommandDump, FetchType } from "command";
|
|
3
|
+
import { Dispatcher } from "dispatcher";
|
|
4
|
+
import { ExtractError, ExtractResponse } from "types";
|
|
5
5
|
export declare const stringifyKey: (value: unknown) => string;
|
|
6
6
|
export declare const getProgressValue: ({ loaded, total }: ClientProgressEvent) => number;
|
|
7
7
|
export declare const getRequestEta: (startDate: Date, progressDate: Date, { total, loaded }: ClientProgressEvent) => {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import EventEmitter from "events";
|
|
3
|
-
import { DispatcherData, DispatcherOptionsType, DispatcherStorageType, DispatcherDumpValueType, RunningRequestValueType } from "
|
|
4
|
-
import { BuilderInstance } from "
|
|
5
|
-
import { CommandInstance } from "
|
|
3
|
+
import { DispatcherData, DispatcherOptionsType, DispatcherStorageType, DispatcherDumpValueType, RunningRequestValueType } from "dispatcher";
|
|
4
|
+
import { BuilderInstance } from "builder";
|
|
5
|
+
import { CommandInstance } from "command";
|
|
6
6
|
/**
|
|
7
7
|
* Dispatcher class was made to store controlled request Fetches, and firing them all-at-once or one-by-one in command queue.
|
|
8
8
|
* Generally requests should be flushed at the same time, the queue provide mechanism to fire them in the order.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import EventEmitter from "events";
|
|
2
|
-
import { DispatcherData } from "
|
|
3
|
-
import { CommandInstance } from "
|
|
2
|
+
import { DispatcherData } from "dispatcher";
|
|
3
|
+
import { CommandInstance } from "command";
|
|
4
4
|
export declare const getDispatcherEvents: (emitter: EventEmitter) => {
|
|
5
5
|
setDrained: <Command extends CommandInstance>(queueKey: string, values: DispatcherData<Command>) => void;
|
|
6
6
|
setQueueStatus: <Command_1 extends CommandInstance>(queueKey: string, values: DispatcherData<Command_1>) => void;
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import { Dispatcher } from "
|
|
2
|
-
import { CommandDump, CommandInstance } from "
|
|
3
|
-
export
|
|
1
|
+
import { Dispatcher } from "dispatcher";
|
|
2
|
+
import { CommandDump, CommandInstance } from "command";
|
|
3
|
+
export type DispatcherOptionsType = {
|
|
4
4
|
storage?: DispatcherStorageType;
|
|
5
5
|
onInitialization?: (dispatcherInstance: Dispatcher) => void;
|
|
6
6
|
onUpdateStorage?: <Command extends CommandInstance>(queueKey: string, data: DispatcherData<Command>) => void;
|
|
7
7
|
onDeleteFromStorage?: <Command extends CommandInstance>(queueKey: string, data: DispatcherData<Command>) => void;
|
|
8
8
|
onClearStorage?: (dispatcherInstance: Dispatcher) => void;
|
|
9
9
|
};
|
|
10
|
-
export
|
|
10
|
+
export type DispatcherDumpValueType<Command extends CommandInstance = CommandInstance> = {
|
|
11
11
|
requestId: string;
|
|
12
12
|
commandDump: CommandDump<Command>;
|
|
13
13
|
retries: number;
|
|
14
14
|
timestamp: number;
|
|
15
15
|
stopped: boolean;
|
|
16
16
|
};
|
|
17
|
-
export
|
|
17
|
+
export type DispatcherData<Command extends CommandInstance = CommandInstance> = {
|
|
18
18
|
requests: DispatcherDumpValueType<Command>[];
|
|
19
19
|
stopped: boolean;
|
|
20
20
|
};
|
|
21
|
-
export
|
|
21
|
+
export type DispatcherStorageType = {
|
|
22
22
|
set: <Command extends CommandInstance = CommandInstance>(key: string, data: DispatcherData<Command>) => void;
|
|
23
23
|
get: <Command extends CommandInstance = CommandInstance>(key: string) => DispatcherData<Command> | undefined;
|
|
24
24
|
keys: () => string[] | IterableIterator<string>;
|
|
25
25
|
delete: (key: string) => void;
|
|
26
26
|
clear: () => void;
|
|
27
27
|
};
|
|
28
|
-
export
|
|
28
|
+
export type RunningRequestValueType = {
|
|
29
29
|
requestId: string;
|
|
30
30
|
command: CommandInstance;
|
|
31
31
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { CommandInstance } from "
|
|
2
|
-
import { ClientResponseType } from "
|
|
3
|
-
import { DispatcherRequestType, DispatcherDumpValueType } from "
|
|
1
|
+
import { CommandInstance } from "command";
|
|
2
|
+
import { ClientResponseType } from "client";
|
|
3
|
+
import { DispatcherRequestType, DispatcherDumpValueType } from "dispatcher";
|
|
4
4
|
export declare const getDispatcherDrainedEventKey: (key: string) => string;
|
|
5
5
|
export declare const getDispatcherStatusEventKey: (key: string) => string;
|
|
6
6
|
export declare const getDispatcherChangeEventKey: (key: string) => string;
|