@hyper-fetch/core 3.1.0 → 3.2.1
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/.eslintrc.json +1 -2
- package/README.md +13 -13
- package/dist/index.d.ts +1273 -11
- package/package.json +2 -2
- package/tsconfig.json +1 -0
- package/dist/adapter/adapter.bindings.d.ts +0 -25
- package/dist/adapter/adapter.browser.d.ts +0 -2
- package/dist/adapter/adapter.constants.d.ts +0 -1
- package/dist/adapter/adapter.d.ts +0 -2
- package/dist/adapter/adapter.server.d.ts +0 -2
- package/dist/adapter/adapter.types.d.ts +0 -57
- package/dist/adapter/adapter.utils.d.ts +0 -8
- package/dist/adapter/index.d.ts +0 -7
- package/dist/cache/cache.d.ts +0 -76
- package/dist/cache/cache.events.d.ts +0 -28
- package/dist/cache/cache.types.d.ts +0 -50
- package/dist/cache/cache.utils.d.ts +0 -6
- package/dist/cache/index.d.ts +0 -4
- package/dist/client/client.constants.d.ts +0 -9
- package/dist/client/client.d.ts +0 -142
- package/dist/client/client.types.d.ts +0 -41
- package/dist/client/client.utils.d.ts +0 -10
- package/dist/client/index.d.ts +0 -4
- package/dist/constants/http.constants.d.ts +0 -7
- package/dist/constants/time.constants.d.ts +0 -11
- package/dist/dispatcher/dispatcher.constants.d.ts +0 -6
- package/dist/dispatcher/dispatcher.d.ts +0 -155
- package/dist/dispatcher/dispatcher.events.d.ts +0 -11
- package/dist/dispatcher/dispatcher.types.d.ts +0 -31
- package/dist/dispatcher/dispatcher.utils.d.ts +0 -10
- package/dist/dispatcher/index.d.ts +0 -5
- package/dist/effect/index.d.ts +0 -2
- package/dist/effect/request.effect.d.ts +0 -14
- package/dist/effect/request.effect.types.d.ts +0 -32
- package/dist/managers/app/app.manager.constants.d.ts +0 -9
- package/dist/managers/app/app.manager.d.ts +0 -34
- package/dist/managers/app/app.manager.events.d.ts +0 -11
- package/dist/managers/app/app.manager.types.d.ts +0 -6
- package/dist/managers/app/app.manager.utils.d.ts +0 -4
- package/dist/managers/app/index.d.ts +0 -5
- package/dist/managers/index.d.ts +0 -3
- package/dist/managers/logger/index.d.ts +0 -4
- package/dist/managers/logger/logger.manager.constants.d.ts +0 -4
- package/dist/managers/logger/logger.manager.d.ts +0 -19
- package/dist/managers/logger/logger.manager.types.d.ts +0 -30
- package/dist/managers/logger/logger.manager.utils.d.ts +0 -3
- package/dist/managers/request/index.d.ts +0 -4
- package/dist/managers/request/request.manager.d.ts +0 -43
- package/dist/managers/request/request.manager.events.d.ts +0 -36
- package/dist/managers/request/request.manager.types.d.ts +0 -23
- package/dist/managers/request/request.manager.utils.d.ts +0 -16
- package/dist/request/index.d.ts +0 -3
- package/dist/request/request.d.ts +0 -98
- package/dist/request/request.types.d.ts +0 -202
- package/dist/request/request.utils.d.ts +0 -22
- package/dist/types/fetch.types.d.ts +0 -16
- package/dist/types/helpers.types.d.ts +0 -11
- package/dist/types/http.types.d.ts +0 -1
- package/dist/types/index.d.ts +0 -3
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/uuid.utils.d.ts +0 -1
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import { RequestSendType, PayloadType, RequestDump, RequestOptionsType, ExtractRouteParams, RequestCurrentType, PayloadMapperType } from "request";
|
|
2
|
-
import { Client } from "client";
|
|
3
|
-
import { QueryParamsType } from "adapter";
|
|
4
|
-
import { HttpMethodsType, NegativeTypes } from "types";
|
|
5
|
-
/**
|
|
6
|
-
* Fetch request it is designed to prepare the necessary setup to execute the request to the server.
|
|
7
|
-
* We can setup basic options for example endpoint, method, headers and advanced settings like cache, invalidation patterns, concurrency, retries and much, much more.
|
|
8
|
-
* :::info Usage
|
|
9
|
-
* We should not use this class directly in the standard development flow. We can initialize it using the `createRequest` method on the **Client** class.
|
|
10
|
-
* :::
|
|
11
|
-
*
|
|
12
|
-
* @attention
|
|
13
|
-
* The most important thing about the request is that it keeps data in the format that can be dumped. This is necessary for the persistence and different dispatcher storage types.
|
|
14
|
-
* This class doesn't have any callback methods by design and communicate with dispatcher and cache by events.
|
|
15
|
-
*/
|
|
16
|
-
export declare class Request<Response, Payload, QueryParams extends QueryParamsType | string, GlobalError, // Global Error Type
|
|
17
|
-
LocalError, // Additional Error for specific endpoint
|
|
18
|
-
Endpoint extends string, AdapterOptions, HasData extends true | false = false, HasParams extends true | false = false, HasQuery extends true | false = false, MappedData = undefined> {
|
|
19
|
-
readonly client: Client<GlobalError, AdapterOptions>;
|
|
20
|
-
readonly requestOptions: RequestOptionsType<Endpoint, AdapterOptions>;
|
|
21
|
-
readonly requestDump?: RequestCurrentType<Response, Payload, QueryParams, GlobalError | LocalError, Endpoint, AdapterOptions, MappedData> | undefined;
|
|
22
|
-
readonly dataMapper?: PayloadMapperType<Payload, MappedData>;
|
|
23
|
-
endpoint: Endpoint;
|
|
24
|
-
headers?: HeadersInit;
|
|
25
|
-
auth: boolean;
|
|
26
|
-
method: HttpMethodsType;
|
|
27
|
-
params: ExtractRouteParams<Endpoint> | NegativeTypes;
|
|
28
|
-
data: PayloadType<Payload, MappedData>;
|
|
29
|
-
queryParams: QueryParams | NegativeTypes;
|
|
30
|
-
options?: AdapterOptions | undefined;
|
|
31
|
-
cancelable: boolean;
|
|
32
|
-
retry: number;
|
|
33
|
-
retryTime: number;
|
|
34
|
-
garbageCollection: number;
|
|
35
|
-
cache: boolean;
|
|
36
|
-
cacheTime: number;
|
|
37
|
-
queued: boolean;
|
|
38
|
-
offline: boolean;
|
|
39
|
-
abortKey: string;
|
|
40
|
-
cacheKey: string;
|
|
41
|
-
queueKey: string;
|
|
42
|
-
effectKey: string;
|
|
43
|
-
used: boolean;
|
|
44
|
-
deduplicate: boolean;
|
|
45
|
-
deduplicateTime: number;
|
|
46
|
-
private updatedAbortKey;
|
|
47
|
-
private updatedCacheKey;
|
|
48
|
-
private updatedQueueKey;
|
|
49
|
-
private updatedEffectKey;
|
|
50
|
-
constructor(client: Client<GlobalError, AdapterOptions>, requestOptions: RequestOptionsType<Endpoint, AdapterOptions>, requestDump?: RequestCurrentType<Response, Payload, QueryParams, GlobalError | LocalError, Endpoint, AdapterOptions, MappedData> | undefined, dataMapper?: PayloadMapperType<Payload, MappedData>);
|
|
51
|
-
setHeaders: (headers: HeadersInit) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, AdapterOptions, HasData, HasParams, HasQuery, MappedData>;
|
|
52
|
-
setAuth: (auth: boolean) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, AdapterOptions, HasData, HasParams, HasQuery, MappedData>;
|
|
53
|
-
setParams: <P extends ExtractRouteParams<Endpoint>>(params: P) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, AdapterOptions, HasData, P extends null ? false : true, HasQuery, MappedData>;
|
|
54
|
-
setData: <D extends Payload>(data: D) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, AdapterOptions, D extends null ? false : true, HasParams, HasQuery, MappedData>;
|
|
55
|
-
setQueryParams: (queryParams: QueryParams) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, AdapterOptions, HasData, HasParams, true, MappedData>;
|
|
56
|
-
setOptions: (options: AdapterOptions) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, AdapterOptions, HasData, HasParams, true, MappedData>;
|
|
57
|
-
setCancelable: (cancelable: boolean) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, AdapterOptions, HasData, HasParams, HasQuery, MappedData>;
|
|
58
|
-
setRetry: (retry: RequestOptionsType<Endpoint, AdapterOptions>["retry"]) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, AdapterOptions, HasData, HasParams, HasQuery, MappedData>;
|
|
59
|
-
setRetryTime: (retryTime: RequestOptionsType<Endpoint, AdapterOptions>["retryTime"]) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, AdapterOptions, HasData, HasParams, HasQuery, MappedData>;
|
|
60
|
-
setGarbageCollection: (garbageCollection: RequestOptionsType<Endpoint, AdapterOptions>["garbageCollection"]) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, AdapterOptions, HasData, HasParams, HasQuery, MappedData>;
|
|
61
|
-
setCache: (cache: RequestOptionsType<Endpoint, AdapterOptions>["cache"]) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, AdapterOptions, HasData, HasParams, HasQuery, MappedData>;
|
|
62
|
-
setCacheTime: (cacheTime: RequestOptionsType<Endpoint, AdapterOptions>["cacheTime"]) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, AdapterOptions, HasData, HasParams, HasQuery, MappedData>;
|
|
63
|
-
setQueued: (queued: boolean) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, AdapterOptions, HasData, HasParams, HasQuery, MappedData>;
|
|
64
|
-
setAbortKey: (abortKey: string) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, AdapterOptions, HasData, HasParams, HasQuery, MappedData>;
|
|
65
|
-
setCacheKey: (cacheKey: string) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, AdapterOptions, HasData, HasParams, HasQuery, MappedData>;
|
|
66
|
-
setQueueKey: (queueKey: string) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, AdapterOptions, HasData, HasParams, HasQuery, MappedData>;
|
|
67
|
-
setEffectKey: (effectKey: string) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, AdapterOptions, HasData, HasParams, HasQuery, MappedData>;
|
|
68
|
-
setDeduplicate: (deduplicate: boolean) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, AdapterOptions, HasData, HasParams, HasQuery, MappedData>;
|
|
69
|
-
setDeduplicateTime: (deduplicateTime: number) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, AdapterOptions, HasData, HasParams, HasQuery, MappedData>;
|
|
70
|
-
setUsed: (used: boolean) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, AdapterOptions, HasData, HasParams, HasQuery, MappedData>;
|
|
71
|
-
setOffline: (offline: boolean) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, AdapterOptions, HasData, HasParams, HasQuery, MappedData>;
|
|
72
|
-
setDataMapper: <DataMapper extends (data: Payload) => any>(mapper: DataMapper) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, AdapterOptions, HasData, HasParams, HasQuery, MappedData>;
|
|
73
|
-
private paramsMapper;
|
|
74
|
-
dump(): RequestDump<Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, AdapterOptions, HasData, HasParams, HasQuery, MappedData>, AdapterOptions, QueryParams>;
|
|
75
|
-
clone<D extends true | false = HasData, P extends true | false = HasParams, Q extends true | false = HasQuery, NewMappedData = MappedData>(options?: RequestCurrentType<Response, Payload, QueryParams, GlobalError | LocalError, Endpoint, AdapterOptions, NewMappedData>, mapper?: PayloadMapperType<Payload, NewMappedData>): Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, AdapterOptions, D, P, Q, NewMappedData>;
|
|
76
|
-
abort: () => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, AdapterOptions, HasData, HasParams, HasQuery, MappedData>;
|
|
77
|
-
/**
|
|
78
|
-
* Method to use the request WITHOUT adding it to cache and queues. This mean it will make simple request without queue side effects.
|
|
79
|
-
* @param options
|
|
80
|
-
* @disableReturns
|
|
81
|
-
* @returns
|
|
82
|
-
* ```tsx
|
|
83
|
-
* Promise<[Data | null, Error | null, HttpStatus]>
|
|
84
|
-
* ```
|
|
85
|
-
*/
|
|
86
|
-
exec: RequestSendType<Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, AdapterOptions, HasData, HasParams, HasQuery, MappedData>>;
|
|
87
|
-
/**
|
|
88
|
-
* Method used to perform requests with usage of cache and queues
|
|
89
|
-
* @param options
|
|
90
|
-
* @param requestCallback
|
|
91
|
-
* @disableReturns
|
|
92
|
-
* @returns
|
|
93
|
-
* ```tsx
|
|
94
|
-
* Promise<[Data | null, Error | null, HttpStatus]>
|
|
95
|
-
* ```
|
|
96
|
-
*/
|
|
97
|
-
send: RequestSendType<Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, AdapterOptions, HasData, HasParams, HasQuery, MappedData>>;
|
|
98
|
-
}
|
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
import { NullableKeys, NegativeTypes, ExtractParamsType, ExtractPayloadType, HttpMethodsType, ExtractQueryParamsType, ExtractAdapterOptionsType, ExtractEndpointType, ExtractHasDataType, ExtractHasParamsType, ExtractHasQueryParamsType, ExtractErrorType, ExtractResponseType } from "types";
|
|
2
|
-
import { Request } from "request";
|
|
3
|
-
import { ResponseType, QueryParamsType, ProgressType } from "adapter";
|
|
4
|
-
import { RequestEventType, ResponseDetailsType } from "managers";
|
|
5
|
-
export type AdapterProgressEventType = {
|
|
6
|
-
total: number;
|
|
7
|
-
loaded: number;
|
|
8
|
-
};
|
|
9
|
-
export type AdapterProgressType = {
|
|
10
|
-
progress: number;
|
|
11
|
-
timeLeft: number;
|
|
12
|
-
sizeLeft: number;
|
|
13
|
-
};
|
|
14
|
-
/**
|
|
15
|
-
* Dump of the request used to later recreate it
|
|
16
|
-
*/
|
|
17
|
-
export type RequestDump<Request extends RequestInstance, AdapterOptions = unknown, QueryParams = QueryParamsType, Params = ExtractParamsType<Request>> = {
|
|
18
|
-
requestOptions: RequestOptionsType<string, AdapterOptions | ExtractAdapterOptionsType<Request>>;
|
|
19
|
-
endpoint: string;
|
|
20
|
-
method: HttpMethodsType;
|
|
21
|
-
headers?: HeadersInit;
|
|
22
|
-
auth: boolean;
|
|
23
|
-
cancelable: boolean;
|
|
24
|
-
retry: number;
|
|
25
|
-
retryTime: number;
|
|
26
|
-
garbageCollection: number;
|
|
27
|
-
cache: boolean;
|
|
28
|
-
cacheTime: number;
|
|
29
|
-
queued: boolean;
|
|
30
|
-
offline: boolean;
|
|
31
|
-
disableResponseInterceptors: boolean | undefined;
|
|
32
|
-
disableRequestInterceptors: boolean | undefined;
|
|
33
|
-
options?: AdapterOptions | ExtractAdapterOptionsType<Request>;
|
|
34
|
-
data: PayloadType<ExtractPayloadType<Request>, unknown>;
|
|
35
|
-
params: Params | NegativeTypes;
|
|
36
|
-
queryParams: QueryParams | NegativeTypes;
|
|
37
|
-
abortKey: string;
|
|
38
|
-
cacheKey: string;
|
|
39
|
-
queueKey: string;
|
|
40
|
-
effectKey: string;
|
|
41
|
-
used: boolean;
|
|
42
|
-
updatedAbortKey: boolean;
|
|
43
|
-
updatedCacheKey: boolean;
|
|
44
|
-
updatedQueueKey: boolean;
|
|
45
|
-
updatedEffectKey: boolean;
|
|
46
|
-
deduplicate: boolean;
|
|
47
|
-
deduplicateTime: number;
|
|
48
|
-
};
|
|
49
|
-
/**
|
|
50
|
-
* Configuration options for request creation
|
|
51
|
-
*/
|
|
52
|
-
export type RequestOptionsType<GenericEndpoint extends string, AdapterOptions> = {
|
|
53
|
-
/**
|
|
54
|
-
* Determine the endpoint for request request
|
|
55
|
-
*/
|
|
56
|
-
endpoint: GenericEndpoint;
|
|
57
|
-
/**
|
|
58
|
-
* Custom headers for request
|
|
59
|
-
*/
|
|
60
|
-
headers?: HeadersInit;
|
|
61
|
-
/**
|
|
62
|
-
* Should the onAuth method get called on this request
|
|
63
|
-
*/
|
|
64
|
-
auth?: boolean;
|
|
65
|
-
/**
|
|
66
|
-
* Request method GET | POST | PATCH | PUT | DELETE
|
|
67
|
-
*/
|
|
68
|
-
method?: HttpMethodsType;
|
|
69
|
-
/**
|
|
70
|
-
* Should enable cancelable mode in the Dispatcher
|
|
71
|
-
*/
|
|
72
|
-
cancelable?: boolean;
|
|
73
|
-
/**
|
|
74
|
-
* Retry count when request is failed
|
|
75
|
-
*/
|
|
76
|
-
retry?: number;
|
|
77
|
-
/**
|
|
78
|
-
* Retry time delay between retries
|
|
79
|
-
*/
|
|
80
|
-
retryTime?: number;
|
|
81
|
-
/**
|
|
82
|
-
* Should we trigger garbage collection or leave data in memory
|
|
83
|
-
*/
|
|
84
|
-
garbageCollection?: number;
|
|
85
|
-
/**
|
|
86
|
-
* Should we save the response to cache
|
|
87
|
-
*/
|
|
88
|
-
cache?: boolean;
|
|
89
|
-
/**
|
|
90
|
-
* Time for which the cache is considered up-to-date
|
|
91
|
-
*/
|
|
92
|
-
cacheTime?: number;
|
|
93
|
-
/**
|
|
94
|
-
* Should the requests from this request be send one-by-one
|
|
95
|
-
*/
|
|
96
|
-
queued?: boolean;
|
|
97
|
-
/**
|
|
98
|
-
* Do we want to store request made in offline mode for latter use when we go back online
|
|
99
|
-
*/
|
|
100
|
-
offline?: boolean;
|
|
101
|
-
/**
|
|
102
|
-
* Disable post-request interceptors
|
|
103
|
-
*/
|
|
104
|
-
disableResponseInterceptors?: boolean;
|
|
105
|
-
/**
|
|
106
|
-
* Disable pre-request interceptors
|
|
107
|
-
*/
|
|
108
|
-
disableRequestInterceptors?: boolean;
|
|
109
|
-
/**
|
|
110
|
-
* Additional options for your adapter, by default XHR options
|
|
111
|
-
*/
|
|
112
|
-
options?: AdapterOptions;
|
|
113
|
-
/**
|
|
114
|
-
* Key which will be used to cancel requests. Autogenerated by default.
|
|
115
|
-
*/
|
|
116
|
-
abortKey?: string;
|
|
117
|
-
/**
|
|
118
|
-
* Key which will be used to cache requests. Autogenerated by default.
|
|
119
|
-
*/
|
|
120
|
-
cacheKey?: string;
|
|
121
|
-
/**
|
|
122
|
-
* Key which will be used to queue requests. Autogenerated by default.
|
|
123
|
-
*/
|
|
124
|
-
queueKey?: string;
|
|
125
|
-
/**
|
|
126
|
-
* Key which will be used to use effects. Autogenerated by default.
|
|
127
|
-
*/
|
|
128
|
-
effectKey?: string;
|
|
129
|
-
/**
|
|
130
|
-
* Should we deduplicate two requests made at the same time into one
|
|
131
|
-
*/
|
|
132
|
-
deduplicate?: boolean;
|
|
133
|
-
/**
|
|
134
|
-
* Time of pooling for the deduplication to be active (default 10ms)
|
|
135
|
-
*/
|
|
136
|
-
deduplicateTime?: number;
|
|
137
|
-
};
|
|
138
|
-
export type PayloadMapperType<PayloadType, MappedData> = (data: PayloadType) => MappedData;
|
|
139
|
-
export type PayloadType<Payload, MappedData> = (MappedData extends never ? Payload : MappedData) | NegativeTypes;
|
|
140
|
-
export type RequestCurrentType<Response, Payload, QueryParams, ErrorType, GenericEndpoint extends string, AdapterOptions, MappedData> = {
|
|
141
|
-
used?: boolean;
|
|
142
|
-
params?: ExtractRouteParams<GenericEndpoint> | NegativeTypes;
|
|
143
|
-
queryParams?: QueryParams | NegativeTypes;
|
|
144
|
-
data?: PayloadType<Payload, MappedData>;
|
|
145
|
-
mockCallback?: ((data: Payload) => ResponseType<Response, ErrorType>) | undefined;
|
|
146
|
-
headers?: HeadersInit;
|
|
147
|
-
updatedAbortKey?: boolean;
|
|
148
|
-
updatedCacheKey?: boolean;
|
|
149
|
-
updatedQueueKey?: boolean;
|
|
150
|
-
updatedEffectKey?: boolean;
|
|
151
|
-
} & Partial<NullableKeys<RequestOptionsType<GenericEndpoint, AdapterOptions>>>;
|
|
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}` ? {
|
|
155
|
-
[k in Param | keyof ExtractRouteParams<Rest>]: ParamType;
|
|
156
|
-
} : T extends `${string}:${infer Param}` ? {
|
|
157
|
-
[k in Param]: ParamType;
|
|
158
|
-
} : NegativeTypes;
|
|
159
|
-
export type FetchOptionsType<AdapterOptions> = Omit<Partial<RequestOptionsType<string, AdapterOptions>>, "endpoint" | "method">;
|
|
160
|
-
/**
|
|
161
|
-
* It will check if the query params are already set
|
|
162
|
-
*/
|
|
163
|
-
export type FetchQueryParamsType<QueryParams extends QueryParamsType | string, HasQuery extends true | false = false> = HasQuery extends true ? {
|
|
164
|
-
queryParams?: NegativeTypes;
|
|
165
|
-
} : {
|
|
166
|
-
queryParams?: QueryParams | string;
|
|
167
|
-
};
|
|
168
|
-
/**
|
|
169
|
-
* If the request endpoint parameters are not filled it will throw an error
|
|
170
|
-
*/
|
|
171
|
-
export type FetchParamsType<Endpoint extends string, HasParams extends true | false> = ExtractRouteParams<Endpoint> extends NegativeTypes ? {
|
|
172
|
-
params?: NegativeTypes;
|
|
173
|
-
} : true extends HasParams ? {
|
|
174
|
-
params?: NegativeTypes;
|
|
175
|
-
} : {
|
|
176
|
-
params: NonNullable<ExtractRouteParams<Endpoint>>;
|
|
177
|
-
};
|
|
178
|
-
/**
|
|
179
|
-
* If the request data is not filled it will throw an error
|
|
180
|
-
*/
|
|
181
|
-
export type FetchPayloadType<Payload, HasData extends true | false> = Payload extends NegativeTypes ? {
|
|
182
|
-
data?: NegativeTypes;
|
|
183
|
-
} : HasData extends true ? {
|
|
184
|
-
data?: NegativeTypes;
|
|
185
|
-
} : {
|
|
186
|
-
data: NonNullable<Payload>;
|
|
187
|
-
};
|
|
188
|
-
export type RequestQueueOptions = {
|
|
189
|
-
dispatcherType?: "auto" | "fetch" | "submit";
|
|
190
|
-
};
|
|
191
|
-
export type RequestSendOptionsType<Request extends RequestInstance> = FetchQueryParamsType<ExtractQueryParamsType<Request>, ExtractHasQueryParamsType<Request>> & FetchParamsType<ExtractEndpointType<Request>, ExtractHasParamsType<Request>> & FetchPayloadType<ExtractPayloadType<Request>, ExtractHasDataType<Request>> & Omit<FetchOptionsType<ExtractAdapterOptionsType<Request>>, "params" | "data"> & FetchSendActionsType<Request> & RequestQueueOptions;
|
|
192
|
-
export type FetchSendActionsType<Request extends RequestInstance> = {
|
|
193
|
-
onSettle?: (requestId: string, request: Request) => void;
|
|
194
|
-
onRequestStart?: (details: RequestEventType<Request>) => void;
|
|
195
|
-
onResponseStart?: (details: RequestEventType<Request>) => void;
|
|
196
|
-
onUploadProgress?: (values: ProgressType, details: RequestEventType<Request>) => void;
|
|
197
|
-
onDownloadProgress?: (values: ProgressType, details: RequestEventType<Request>) => void;
|
|
198
|
-
onResponse?: (response: ResponseType<ExtractResponseType<Request>, ExtractErrorType<Request>>, details: ResponseDetailsType) => void;
|
|
199
|
-
onRemove?: (details: RequestEventType<Request>) => void;
|
|
200
|
-
};
|
|
201
|
-
export type RequestSendType<Request extends RequestInstance> = RequestSendOptionsType<Request>["data"] extends NegativeTypes ? RequestSendOptionsType<Request>["params"] extends NegativeTypes ? (options?: RequestSendOptionsType<Request>) => Promise<ResponseType<ExtractResponseType<Request>, ExtractErrorType<Request>>> : (options: RequestSendOptionsType<Request>) => Promise<ResponseType<ExtractResponseType<Request>, ExtractErrorType<Request>>> : (options: RequestSendOptionsType<Request>) => Promise<ResponseType<ExtractResponseType<Request>, ExtractErrorType<Request>>>;
|
|
202
|
-
export type RequestInstance = Request<any, any, any, any, any, any, any, any, any, any, any>;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { ProgressType, ResponseType } from "adapter";
|
|
2
|
-
import { AdapterProgressEventType, RequestInstance, RequestDump, RequestSendOptionsType } from "request";
|
|
3
|
-
import { Dispatcher } from "dispatcher";
|
|
4
|
-
import { ExtractErrorType, ExtractResponseType } from "types";
|
|
5
|
-
export declare const stringifyKey: (value: unknown) => string;
|
|
6
|
-
export declare const getProgressValue: ({ loaded, total }: AdapterProgressEventType) => number;
|
|
7
|
-
export declare const getRequestEta: (startDate: Date, progressDate: Date, { total, loaded }: AdapterProgressEventType) => {
|
|
8
|
-
sizeLeft: number;
|
|
9
|
-
timeLeft: number | null;
|
|
10
|
-
};
|
|
11
|
-
export declare const getProgressData: (requestStartTime: Date, progressDate: Date, progressEvent: AdapterProgressEventType) => ProgressType;
|
|
12
|
-
export declare const getSimpleKey: (request: RequestInstance | RequestDump<RequestInstance>) => string;
|
|
13
|
-
/**
|
|
14
|
-
* Cache instance for individual request that collects individual requests responses from
|
|
15
|
-
* the same endpoint (they may differ base on the custom key, endpoint params etc)
|
|
16
|
-
* @param request
|
|
17
|
-
* @param useInitialValues
|
|
18
|
-
* @returns
|
|
19
|
-
*/
|
|
20
|
-
export declare const getRequestKey: (request: RequestInstance | RequestDump<RequestInstance>, useInitialValues?: boolean) => string;
|
|
21
|
-
export declare const getRequestDispatcher: <Request_1 extends RequestInstance>(request: Request_1, dispatcherType?: "auto" | "fetch" | "submit") => [Dispatcher, boolean];
|
|
22
|
-
export declare const requestSendRequest: <Request_1 extends RequestInstance>(request: Request_1, options?: RequestSendOptionsType<Request_1>) => Promise<ResponseType<ExtractResponseType<Request_1>, ExtractErrorType<Request_1>>>;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { ResponseType } from "adapter";
|
|
2
|
-
import { ExtractRouteParams, Request, RequestInstance } from "request";
|
|
3
|
-
export type ExtractAdapterReturnType<T extends RequestInstance> = ResponseType<ExtractResponseType<T>, ExtractErrorType<T>>;
|
|
4
|
-
export type ExtractResponseType<T> = T extends Request<infer D, any, any, any, any, any, any, any, any, any, any> ? D : never;
|
|
5
|
-
export type ExtractPayloadType<T> = T extends Request<any, infer D, any, any, any, any, any, any, any, any, any> ? D : never;
|
|
6
|
-
export type ExtractQueryParamsType<T> = T extends Request<any, any, infer Q, any, any, any, any, any, any, any, any> ? Q : never;
|
|
7
|
-
export type ExtractErrorType<T> = T extends Request<any, any, any, infer G, infer L, any, any, any, any, any, any> ? G | L : never;
|
|
8
|
-
export type ExtractGlobalErrorType<T> = T extends Request<any, any, any, infer E, any, any, any, any, any, any, any> ? E : never;
|
|
9
|
-
export type ExtractLocalErrorType<T> = T extends Request<any, any, any, any, infer E, any, any, any, any, any, any> ? E : never;
|
|
10
|
-
export type ExtractParamsType<T> = T extends Request<any, any, any, any, any, infer P, any, any, any, any, any> ? ExtractRouteParams<P> : never;
|
|
11
|
-
export type ExtractEndpointType<T> = T extends Request<any, any, any, any, any, infer E, any, any, any, any, any> ? E : never;
|
|
12
|
-
export type ExtractAdapterOptionsType<T> = T extends Request<any, any, any, any, any, any, infer O, any, any, any, any> ? O : never;
|
|
13
|
-
export type ExtractHasDataType<T> = T extends Request<any, any, any, any, any, any, any, infer D, any, any, any> ? D : never;
|
|
14
|
-
export type ExtractHasParamsType<T> = T extends Request<any, any, any, any, any, any, any, any, infer P, any, any> ? P : never;
|
|
15
|
-
export type ExtractHasQueryParamsType<T> = T extends Request<any, any, any, any, any, any, any, any, any, infer Q, any> ? Q : never;
|
|
16
|
-
export type ExtractHasMappedDataType<T> = T extends Request<any, any, any, any, any, any, any, any, any, any, infer M> ? M : never;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export type NegativeTypes = null | undefined;
|
|
2
|
-
export type NullableType<T> = T | NegativeTypes;
|
|
3
|
-
export type NullableKeys<T> = {
|
|
4
|
-
[P in keyof T]-?: NullableType<T[P]>;
|
|
5
|
-
};
|
|
6
|
-
export type NonNullableKeys<T> = {
|
|
7
|
-
[P in keyof T]-?: NonNullable<T[P]>;
|
|
8
|
-
};
|
|
9
|
-
export type RequiredKeys<T> = {
|
|
10
|
-
[P in keyof T]-?: Exclude<T[P], NegativeTypes>;
|
|
11
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type HttpMethodsType = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
package/dist/types/index.d.ts
DELETED
package/dist/utils/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./uuid.utils";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const getUniqueRequestId: (key: string) => string;
|