@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.
Files changed (60) hide show
  1. package/README.md +3 -2
  2. package/dist/builder/builder.d.ts +17 -18
  3. package/dist/builder/builder.types.d.ts +14 -18
  4. package/dist/builder/builder.utils.d.ts +3 -3
  5. package/dist/cache/cache.d.ts +5 -5
  6. package/dist/cache/cache.events.d.ts +1 -1
  7. package/dist/cache/cache.types.d.ts +9 -9
  8. package/dist/cache/cache.utils.d.ts +2 -2
  9. package/dist/client/fetch.client.bindings.d.ts +5 -5
  10. package/dist/client/fetch.client.browser.d.ts +2 -0
  11. package/dist/client/fetch.client.d.ts +1 -1
  12. package/dist/client/fetch.client.server.d.ts +2 -0
  13. package/dist/client/fetch.client.types.d.ts +15 -15
  14. package/dist/client/fetch.client.utils.d.ts +5 -2
  15. package/dist/client/index.d.ts +1 -0
  16. package/dist/command/command.d.ts +11 -11
  17. package/dist/command/command.types.d.ts +27 -26
  18. package/dist/command/command.utils.d.ts +4 -4
  19. package/dist/dispatcher/dispatcher.d.ts +3 -3
  20. package/dist/dispatcher/dispatcher.events.d.ts +2 -2
  21. package/dist/dispatcher/dispatcher.types.d.ts +7 -7
  22. package/dist/dispatcher/dispatcher.utils.d.ts +3 -3
  23. package/dist/effect/fetch.effect.d.ts +4 -4
  24. package/dist/effect/fetch.effect.types.d.ts +7 -7
  25. package/dist/index.cjs.js +1 -1
  26. package/dist/index.cjs.js.map +4 -4
  27. package/dist/index.d.ts +1 -0
  28. package/dist/index.esm.js +1 -1
  29. package/dist/index.esm.js.map +4 -4
  30. package/dist/managers/app/app.manager.constants.d.ts +2 -2
  31. package/dist/managers/app/app.manager.d.ts +3 -4
  32. package/dist/managers/app/app.manager.types.d.ts +3 -4
  33. package/dist/managers/command/command.manager.d.ts +21 -21
  34. package/dist/managers/command/command.manager.events.d.ts +3 -3
  35. package/dist/managers/command/command.manager.types.d.ts +5 -5
  36. package/dist/managers/logger/logger.manager.d.ts +3 -3
  37. package/dist/managers/logger/logger.manager.types.d.ts +12 -12
  38. package/dist/managers/logger/logger.manager.utils.d.ts +1 -1
  39. package/dist/types/fetch.types.d.ts +16 -15
  40. package/dist/types/helpers.types.d.ts +5 -5
  41. package/dist/types/http.types.d.ts +1 -1
  42. package/package.json +5 -5
  43. package/release.config.js +0 -2
  44. package/src/builder/builder.ts +48 -50
  45. package/src/builder/builder.types.ts +1 -5
  46. package/src/cache/cache.ts +24 -17
  47. package/src/cache/cache.types.ts +1 -1
  48. package/src/client/fetch.client.bindings.ts +5 -5
  49. package/src/client/fetch.client.browser.ts +89 -0
  50. package/src/client/fetch.client.server.ts +105 -0
  51. package/src/client/fetch.client.ts +5 -94
  52. package/src/client/fetch.client.utils.ts +31 -0
  53. package/src/client/index.ts +1 -0
  54. package/src/command/command.ts +60 -18
  55. package/src/command/command.types.ts +14 -14
  56. package/src/index.ts +1 -0
  57. package/src/managers/app/app.manager.ts +7 -5
  58. package/src/managers/app/app.manager.types.ts +2 -4
  59. package/src/managers/logger/logger.manager.ts +1 -1
  60. 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/Architecture/Cache)
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/Architecture/Client)
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 "../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";
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 baseUrl: string;
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("../managers").LoggerType;
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 "../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";
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 declare type BuilderConfig = {
11
+ export type BuilderConfig = {
12
12
  /**
13
13
  * Url to your server
14
14
  */
15
- baseUrl: string;
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 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;
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 "../client";
2
- import { CommandInstance } from "../command";
3
- import { NegativeTypes } from "../types";
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>;
@@ -1,11 +1,11 @@
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";
7
- import { CacheOptionsType, CacheAsyncStorageType, CacheStorageType, getCacheEvents, CacheValueType } from "./";
8
- import { CommandDump, CommandInstance } from "../command";
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,5 +1,5 @@
1
1
  import EventEmitter from "events";
2
- import { CacheValueType } from "./";
2
+ import { CacheValueType } from "cache";
3
3
  export declare const getCacheEvents: (emitter: EventEmitter) => {
4
4
  /**
5
5
  * Set cache data
@@ -1,7 +1,7 @@
1
- import { Cache } from "./";
2
- import { ClientResponseType } from "../client";
3
- import { CommandResponseDetails } from "../managers";
4
- export declare type CacheOptionsType = {
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 declare type CacheValueType<Response = any, Error = any> = {
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: boolean;
35
+ garbageCollection: number;
36
36
  };
37
- export declare type CacheAsyncStorageType = {
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 declare type CacheStorageType = {
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 declare type CacheInitialData = Record<string, CacheValueType>;
50
+ export type CacheInitialData = Record<string, CacheValueType>;
@@ -1,5 +1,5 @@
1
- import { CommandInstance } from "../command";
2
- import { ExtractClientReturnType } from "../types";
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 "../command";
3
- import { ExtractResponse, ExtractError } from "../types";
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: any;
8
+ config: ConfigType;
9
9
  getAbortController: () => AbortController;
10
10
  getRequestStartTimestamp: () => number;
11
11
  getResponseStartTimestamp: () => number;
@@ -0,0 +1,2 @@
1
+ import { ClientType } from "client";
2
+ export declare const browserClient: ClientType;
@@ -1,2 +1,2 @@
1
- import { ClientType } from "./";
1
+ import { ClientType } from "client";
2
2
  export declare const fetchClient: ClientType;
@@ -0,0 +1,2 @@
1
+ import { ClientType } from "client";
2
+ export declare const serverClient: ClientType;
@@ -1,23 +1,23 @@
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> = [
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 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 = {
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 declare type QueryStringifyOptions = {
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 declare type ProgressRequestDataType = {
46
+ export type ProgressRequestDataType = {
47
47
  total?: number;
48
48
  loaded?: number;
49
49
  };
50
- export declare type FetchProgressType = {
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 "../command";
2
- import { ExtractError } from "../types";
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)[]>;
@@ -1,5 +1,6 @@
1
1
  export * from "./fetch.client";
2
2
  export * from "./fetch.client.types";
3
3
  export * from "./fetch.client.utils";
4
+ export * from "./fetch.client.browser";
4
5
  export * from "./fetch.client.bindings";
5
6
  export * from "./fetch.client.constants";
@@ -1,7 +1,7 @@
1
- import { FetchMethodType, CommandData, CommandDump, CommandConfig, ExtractRouteParams, CommandCurrentType } from "./";
2
- import { Builder } from "../builder";
3
- import { ClientQueryParamsType } from "../client";
4
- import { HttpMethodsType, NegativeTypes } from "../types";
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?: (data: RequestDataType) => MappedData;
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: boolean;
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?: (data: RequestDataType) => MappedData);
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: ExtractRouteParams<EndpointType>) => Command<ResponseType, RequestDataType, QueryParamsType, GlobalErrorType, LocalErrorType, EndpointType, ClientOptions, HasData, true, HasQuery, MappedData>;
54
- setData: (data: RequestDataType) => Command<ResponseType, RequestDataType, QueryParamsType, GlobalErrorType, LocalErrorType, EndpointType, ClientOptions, true, HasParams, HasQuery, MappedData>;
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>(mapper: (data: RequestDataType) => DataMapper) => Command<ResponseType, RequestDataType, QueryParamsType, GlobalErrorType, LocalErrorType, EndpointType, ClientOptions, HasData, HasParams, HasQuery, 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, MapperData = MappedData>(options?: CommandCurrentType<ResponseType, RequestDataType, QueryParamsType, GlobalErrorType | LocalErrorType, EndpointType, ClientOptions, MapperData>, mapper?: (data: RequestDataType) => MapperData): Command<ResponseType, RequestDataType, QueryParamsType, GlobalErrorType, LocalErrorType, EndpointType, ClientOptions, D, P, Q, MapperData>;
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 "../types";
2
- import { Command } from "./";
3
- import { ClientResponseType, ClientQueryParamsType, FetchProgressType } from "../client";
4
- import { CommandEventDetails, CommandResponseDetails } from "../managers";
5
- export declare type ClientProgressEvent = {
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 declare type ClientProgressResponse = {
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 declare type CommandDump<Command extends CommandInstance, ClientOptions = unknown, QueryParamsType = ClientQueryParamsType, Params = ExtractParams<Command>> = {
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: boolean;
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 declare type CommandConfig<GenericEndpoint extends string, ClientOptions> = {
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?: boolean;
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 declare type CommandData<RequestDataType, MappedData> = (MappedData extends undefined ? RequestDataType : MappedData) | NegativeTypes;
139
- export declare type CommandCurrentType<ResponseType, RequestDataType, QueryParamsType, ErrorType, GenericEndpoint extends string, ClientOptions, MappedData> = {
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 declare type ParamType = string | number;
152
- export declare type ParamsType = Record<string, ParamType>;
153
- export declare type ExtractRouteParams<T extends string> = string extends T ? NegativeTypes : T extends `${string}:${infer Param}/${infer Rest}` ? {
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 declare type FetchOptionsType<ClientOptions> = Omit<Partial<CommandConfig<string, ClientOptions>>, "endpoint" | "method">;
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 declare type FetchQueryParamsType<QueryParamsType, HasQuery extends true | false = false> = HasQuery extends true ? {
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 declare type FetchParamsType<EndpointType extends string, HasParams extends true | false = false> = ExtractRouteParams<EndpointType> extends NegativeTypes ? {
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 declare type FetchRequestDataType<RequestDataType, HasData extends true | false = false> = RequestDataType extends NegativeTypes ? {
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 declare type CommandQueueOptions = {
188
+ export type CommandQueueOptions = {
188
189
  dispatcherType?: "auto" | "fetch" | "submit";
189
190
  };
190
- export declare 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;
191
- export declare type FetchSendActionsType<Command extends CommandInstance> = {
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 declare type FetchMethodType<Command extends CommandInstance> = FetchType<Command>["data"] extends any ? (options?: FetchType<Command>) => Promise<ClientResponseType<ExtractResponse<Command>, ExtractError<Command>>> : 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>>>;
201
- export declare type CommandInstance = Command<any, any, any, any, any, any, any, any, any, any, any>;
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 "../client";
2
- import { ClientProgressEvent, CommandInstance, CommandDump, FetchType } from "./";
3
- import { Dispatcher } from "../dispatcher";
4
- import { ExtractError, ExtractResponse } from "../types";
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 "../builder";
5
- import { CommandInstance } from "../command";
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 "../command";
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 "../command";
3
- export declare type DispatcherOptionsType = {
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 declare type DispatcherDumpValueType<Command extends CommandInstance = CommandInstance> = {
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 declare type DispatcherData<Command extends CommandInstance = CommandInstance> = {
17
+ export type DispatcherData<Command extends CommandInstance = CommandInstance> = {
18
18
  requests: DispatcherDumpValueType<Command>[];
19
19
  stopped: boolean;
20
20
  };
21
- export declare type DispatcherStorageType = {
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 declare type RunningRequestValueType = {
28
+ export type RunningRequestValueType = {
29
29
  requestId: string;
30
30
  command: CommandInstance;
31
31
  };
@@ -1,6 +1,6 @@
1
- import { CommandInstance } from "../command";
2
- import { ClientResponseType } from "../client";
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;