@hyper-fetch/core 8.1.1 → 8.2.2
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 +137 -52
- package/__tests__/e2e/e2e.advanced.spec.ts +7 -7
- package/__tests__/features/adapter/adapter.base.spec.ts +2 -1
- package/__tests__/features/adapter/adapter.bindings.spec.ts +4 -4
- package/__tests__/features/adapter/adapter.browser.spec.ts +0 -1
- package/__tests__/features/adapter/adapter.server.spec.ts +4 -5
- package/__tests__/features/adapter/adapter.utils.spec.ts +6 -7
- package/__tests__/features/cache/cache.base.spec.ts +7 -7
- package/__tests__/features/cache/cache.events.spec.ts +15 -15
- package/__tests__/features/cache/cache.garbage-collector.spec.ts +18 -18
- package/__tests__/features/cache/cache.lazy-storage.spec.ts +8 -8
- package/__tests__/features/cache/cache.modes.spec.ts +7 -6
- package/__tests__/features/cache/cache.scoping.spec.ts +12 -8
- package/__tests__/features/cache/cache.typescript.spec.ts +2 -2
- package/__tests__/features/cache/cache.utils.spec.ts +14 -14
- package/__tests__/features/client/client.auth.spec.ts +0 -1
- package/__tests__/features/client/client.base.spec.ts +2 -3
- package/__tests__/features/client/client.from-json.spec.ts +0 -1
- package/__tests__/features/client/client.hydration.spec.ts +5 -5
- package/__tests__/features/client/client.interceptor.spec.ts +3 -3
- package/__tests__/features/client/client.methods.spec.ts +5 -5
- package/__tests__/features/client/client.middleware.spec.ts +2 -2
- package/__tests__/features/client/client.utils.spec.ts +16 -15
- package/__tests__/features/dispatcher/dispatcher.base.spec.ts +3 -3
- package/__tests__/features/dispatcher/dispatcher.custom-storage.spec.ts +4 -5
- package/__tests__/features/dispatcher/dispatcher.events.spec.ts +4 -4
- package/__tests__/features/dispatcher/dispatcher.queue.spec.ts +13 -13
- package/__tests__/features/dispatcher/dispatcher.requests.spec.ts +10 -10
- package/__tests__/features/dispatcher/dispatcher.utils.spec.ts +35 -8
- package/__tests__/features/managers/app/app.manager.base.spec.ts +2 -3
- package/__tests__/features/managers/logger/logger.base.spec.ts +1 -2
- package/__tests__/features/managers/request/request.manager.base.spec.ts +8 -9
- package/__tests__/features/managers/request/request.manager.events.spec.ts +1 -2
- package/__tests__/features/mocker/mocker.base.spec.ts +6 -6
- package/__tests__/features/plugin/plugin.base.spec.ts +1 -2
- package/__tests__/features/request/request.cloning.spec.ts +0 -1
- package/__tests__/features/request/request.deduplicate-defaults.spec.ts +79 -0
- package/__tests__/features/request/request.retry-on-error.spec.ts +1 -2
- package/__tests__/features/request/request.sending.spec.ts +73 -24
- package/__tests__/features/request/request.setters.spec.ts +4 -3
- package/__tests__/features/request/request.typescript.spec.ts +0 -1
- package/__tests__/features/request/request.utils.spec.ts +1 -0
- package/__tests__/features/sdk/sdk.base.spec.ts +7 -12
- package/__tests__/features/sdk/sdk.configuration.spec.ts +5 -7
- package/__tests__/features/sdk/sdk.request-fields.spec.ts +80 -0
- package/__tests__/features/sdk/sdk.types.spec.ts +283 -0
- package/__tests__/shared/callbacks.shared.ts +1 -1
- package/__tests__/tsconfig.json +4 -17
- package/__tests__/utils/adapter.utils.ts +1 -2
- package/__tests__/utils/callbacks.utils.ts +1 -2
- package/__tests__/utils/dispatcher.utils.ts +1 -1
- package/__tests__/vitest.setup.ts +1 -1
- package/dist/adapter/adapter.d.ts +22 -5
- package/dist/adapter/adapter.d.ts.map +1 -1
- package/dist/adapter/adapter.types.d.ts +9 -1
- package/dist/adapter/adapter.types.d.ts.map +1 -1
- package/dist/adapter/adapter.utils.d.ts.map +1 -1
- package/dist/cache/cache.d.ts +6 -9
- package/dist/cache/cache.d.ts.map +1 -1
- package/dist/cache/cache.events.d.ts +7 -4
- package/dist/cache/cache.events.d.ts.map +1 -1
- package/dist/cache/cache.types.d.ts +1 -0
- package/dist/cache/cache.types.d.ts.map +1 -1
- package/dist/client/client.create.d.ts +1 -1
- package/dist/client/client.create.d.ts.map +1 -1
- package/dist/client/client.d.ts +8 -4
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/client.types.d.ts +1 -1
- package/dist/client/client.types.d.ts.map +1 -1
- package/dist/client/client.utils.d.ts.map +1 -1
- package/dist/constants/http.constants.d.ts +5 -1
- package/dist/constants/http.constants.d.ts.map +1 -1
- package/dist/constants/time.constants.d.ts.map +1 -1
- package/dist/dispatcher/dispatcher.d.ts +4 -4
- package/dist/dispatcher/dispatcher.d.ts.map +1 -1
- package/dist/dispatcher/dispatcher.events.d.ts +1 -1
- package/dist/dispatcher/dispatcher.events.d.ts.map +1 -1
- package/dist/dispatcher/dispatcher.utils.d.ts +1 -1
- package/dist/dispatcher/dispatcher.utils.d.ts.map +1 -1
- package/dist/http-adapter/http-adapter.constants.d.ts.map +1 -1
- package/dist/http-adapter/http-adapter.d.ts.map +1 -1
- package/dist/http-adapter/http-adapter.fetch.d.ts +2 -2
- package/dist/http-adapter/http-adapter.fetch.d.ts.map +1 -1
- package/dist/http-adapter/http-adapter.types.d.ts +2 -2
- package/dist/http-adapter/http-adapter.types.d.ts.map +1 -1
- package/dist/http-adapter/http-adapter.utils.d.ts.map +1 -1
- package/dist/index.mjs +2382 -2301
- package/dist/index.mjs.map +1 -1
- package/dist/managers/app/app.manager.constants.d.ts +1 -1
- package/dist/managers/app/app.manager.constants.d.ts.map +1 -1
- package/dist/managers/app/app.manager.d.ts +1 -1
- package/dist/managers/app/app.manager.d.ts.map +1 -1
- package/dist/managers/app/app.manager.events.d.ts +9 -0
- package/dist/managers/app/app.manager.events.d.ts.map +1 -1
- package/dist/managers/logger/logger.manager.d.ts +1 -1
- package/dist/managers/logger/logger.manager.d.ts.map +1 -1
- package/dist/managers/request/request.manager.d.ts.map +1 -1
- package/dist/managers/request/request.manager.events.d.ts +14 -3
- package/dist/managers/request/request.manager.events.d.ts.map +1 -1
- package/dist/mocker/mocker.types.d.ts +1 -0
- package/dist/mocker/mocker.types.d.ts.map +1 -1
- package/dist/plugin/plugin.d.ts +17 -1
- package/dist/plugin/plugin.d.ts.map +1 -1
- package/dist/plugin/plugin.types.d.ts +5 -4
- package/dist/plugin/plugin.types.d.ts.map +1 -1
- package/dist/request/request.d.ts +33 -4
- package/dist/request/request.d.ts.map +1 -1
- package/dist/request/request.hooks.d.ts +2 -2
- package/dist/request/request.hooks.d.ts.map +1 -1
- package/dist/request/request.types.d.ts +92 -5
- package/dist/request/request.types.d.ts.map +1 -1
- package/dist/request/request.utils.d.ts.map +1 -1
- package/dist/sdk/sdk.d.ts +25 -5
- package/dist/sdk/sdk.d.ts.map +1 -1
- package/dist/types/http.types.d.ts +1 -1
- package/dist/types/http.types.d.ts.map +1 -1
- package/dist/types/request.types.d.ts +2 -2
- package/dist/types/request.types.d.ts.map +1 -1
- package/dist/utils/emitter.utils.d.ts +1 -1
- package/dist/utils/emitter.utils.d.ts.map +1 -1
- package/package.json +8 -8
- package/src/adapter/adapter.bindings.ts +14 -14
- package/src/adapter/adapter.ts +28 -10
- package/src/adapter/adapter.types.ts +10 -1
- package/src/adapter/adapter.utils.ts +5 -5
- package/src/cache/cache.events.ts +7 -5
- package/src/cache/cache.ts +14 -17
- package/src/cache/cache.types.ts +1 -0
- package/src/client/client.create.ts +1 -1
- package/src/client/client.ts +14 -9
- package/src/client/client.types.ts +2 -2
- package/src/client/client.utils.ts +3 -2
- package/src/constants/http.constants.ts +5 -0
- package/src/constants/time.constants.ts +1 -1
- package/src/dispatcher/dispatcher.events.ts +1 -2
- package/src/dispatcher/dispatcher.ts +13 -13
- package/src/dispatcher/dispatcher.utils.ts +10 -4
- package/src/http-adapter/http-adapter.constants.ts +1 -0
- package/src/http-adapter/http-adapter.fetch.ts +19 -9
- package/src/http-adapter/http-adapter.ts +2 -1
- package/src/http-adapter/http-adapter.types.ts +3 -2
- package/src/http-adapter/http-adapter.utils.ts +15 -11
- package/src/managers/app/app.manager.constants.ts +2 -1
- package/src/managers/app/app.manager.events.ts +9 -1
- package/src/managers/app/app.manager.ts +1 -1
- package/src/managers/app/app.manager.utils.ts +2 -2
- package/src/managers/logger/logger.manager.ts +1 -2
- package/src/managers/request/request.manager.events.ts +14 -12
- package/src/managers/request/request.manager.ts +4 -4
- package/src/mocker/mocker.ts +2 -2
- package/src/mocker/mocker.types.ts +1 -0
- package/src/plugin/plugin.ts +17 -1
- package/src/plugin/plugin.types.ts +5 -4
- package/src/request/request.hooks.ts +6 -5
- package/src/request/request.ts +77 -34
- package/src/request/request.types.ts +107 -5
- package/src/request/request.utils.ts +17 -16
- package/src/sdk/sdk.ts +79 -23
- package/src/types/http.types.ts +1 -1
- package/src/types/request.types.ts +3 -2
- package/src/utils/emitter.utils.ts +1 -1
- package/src/utils/uuid.utils.ts +1 -1
- package/tsconfig.json +30 -2
- package/vite.config.ts +14 -20
- package/.eslintrc.cjs +0 -12
- package/tsconfig.base.json +0 -7
package/src/sdk/sdk.ts
CHANGED
|
@@ -1,12 +1,52 @@
|
|
|
1
1
|
import type { ClientInstance } from "client";
|
|
2
2
|
import type { RequestInstance } from "request";
|
|
3
|
-
import
|
|
3
|
+
import { Request } from "request";
|
|
4
|
+
import type {
|
|
5
|
+
ExtractEndpointType,
|
|
6
|
+
ExtractResponseType,
|
|
7
|
+
ExtractPayloadType,
|
|
8
|
+
ExtractQueryParamsType,
|
|
9
|
+
ExtractLocalErrorType,
|
|
10
|
+
ExtractHasPayloadType,
|
|
11
|
+
ExtractHasParamsType,
|
|
12
|
+
ExtractHasQueryParamsType,
|
|
13
|
+
ExtractMutationContextType,
|
|
14
|
+
} from "types";
|
|
4
15
|
|
|
5
16
|
export type RecursiveSchemaType = Record<
|
|
6
17
|
string, // for example users / $userId / posts / $postId
|
|
7
18
|
any
|
|
8
19
|
>;
|
|
9
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Recursively walks a schema and rebuilds every `Request` leaf with the SDK's actual client
|
|
23
|
+
* type injected into the `Client` generic slot. Lets users omit `client` from their
|
|
24
|
+
* `RequestModel<{...}>` declarations - the SDK fills it in from the client passed to
|
|
25
|
+
* `createSdk(client)`.
|
|
26
|
+
*
|
|
27
|
+
* Non-Request leaves (primitive values, plain types) are passed through unchanged. Nested
|
|
28
|
+
* schema objects are recursed into. Depth is guarded at 10 levels to keep the type checker
|
|
29
|
+
* within reasonable bounds.
|
|
30
|
+
*/
|
|
31
|
+
export type InjectClient<T, TClient extends ClientInstance, Depth extends unknown[] = []> = Depth["length"] extends 10
|
|
32
|
+
? T
|
|
33
|
+
: T extends RequestInstance
|
|
34
|
+
? Request<
|
|
35
|
+
ExtractResponseType<T>,
|
|
36
|
+
ExtractPayloadType<T>,
|
|
37
|
+
ExtractQueryParamsType<T>,
|
|
38
|
+
ExtractLocalErrorType<T>,
|
|
39
|
+
ExtractEndpointType<T> extends string ? ExtractEndpointType<T> : string,
|
|
40
|
+
TClient,
|
|
41
|
+
ExtractHasPayloadType<T> extends boolean ? ExtractHasPayloadType<T> : false,
|
|
42
|
+
ExtractHasParamsType<T> extends boolean ? ExtractHasParamsType<T> : false,
|
|
43
|
+
ExtractHasQueryParamsType<T> extends boolean ? ExtractHasQueryParamsType<T> : false,
|
|
44
|
+
ExtractMutationContextType<T>
|
|
45
|
+
>
|
|
46
|
+
: T extends Record<string, any>
|
|
47
|
+
? { [K in keyof T]: InjectClient<T[K], TClient, [...Depth, unknown]> }
|
|
48
|
+
: T;
|
|
49
|
+
|
|
10
50
|
/**
|
|
11
51
|
* Per-request defaults that can be applied via SDK configuration.
|
|
12
52
|
* These mirror the chainable setters on Request (headers, cache, retry, etc.).
|
|
@@ -97,14 +137,16 @@ export type CreateSdkOptions<Schema extends RecursiveSchemaType = RecursiveSchem
|
|
|
97
137
|
defaults?: SdkConfigurationMap<Schema>;
|
|
98
138
|
};
|
|
99
139
|
|
|
140
|
+
const OPTIONAL_REQUEST_FIELDS = Request.OPTIONAL_FIELDS;
|
|
141
|
+
|
|
100
142
|
const getMethod = (key: string, options?: CreateSdkOptions<any>) => {
|
|
101
143
|
const { methodTransform = (method: string) => method.toUpperCase() } = options ?? {};
|
|
102
144
|
return methodTransform(key);
|
|
103
145
|
};
|
|
104
146
|
|
|
105
147
|
const endpointMatchesPattern = (endpoint: string, pattern: string): boolean => {
|
|
106
|
-
if (pattern === "*") return true;
|
|
107
|
-
if (pattern === endpoint) return true;
|
|
148
|
+
if (pattern === "*") {return true;}
|
|
149
|
+
if (pattern === endpoint) {return true;}
|
|
108
150
|
// Simple wildcard: "/users/*" matches "/users/:userId", "/users/:userId/posts", etc.
|
|
109
151
|
if (pattern.endsWith("/*")) {
|
|
110
152
|
const prefix = pattern.slice(0, -1);
|
|
@@ -119,17 +161,17 @@ const isDotPath = (key: string): boolean => {
|
|
|
119
161
|
|
|
120
162
|
const applyObjectDefaults = (request: RequestInstance, config: SdkRequestDefaults): RequestInstance => {
|
|
121
163
|
let result = request;
|
|
122
|
-
if (config.headers) result = result.setHeaders(config.headers);
|
|
123
|
-
if (config.auth !== undefined) result = result.setAuth(config.auth);
|
|
124
|
-
if (config.cache !== undefined) result = result.setCache(config.cache);
|
|
125
|
-
if (config.cacheTime !== undefined) result = result.setCacheTime(config.cacheTime);
|
|
126
|
-
if (config.staleTime !== undefined) result = result.setStaleTime(config.staleTime);
|
|
127
|
-
if (config.retry !== undefined) result = result.setRetry(config.retry);
|
|
128
|
-
if (config.retryTime !== undefined) result = result.setRetryTime(config.retryTime);
|
|
129
|
-
if (config.cancelable !== undefined) result = result.setCancelable(config.cancelable);
|
|
130
|
-
if (config.queued !== undefined) result = result.setQueued(config.queued);
|
|
131
|
-
if (config.offline !== undefined) result = result.setOffline(config.offline);
|
|
132
|
-
if (config.deduplicate !== undefined) result = result.setDeduplicate(config.deduplicate);
|
|
164
|
+
if (config.headers) {result = result.setHeaders(config.headers);}
|
|
165
|
+
if (config.auth !== undefined) {result = result.setAuth(config.auth);}
|
|
166
|
+
if (config.cache !== undefined) {result = result.setCache(config.cache);}
|
|
167
|
+
if (config.cacheTime !== undefined) {result = result.setCacheTime(config.cacheTime);}
|
|
168
|
+
if (config.staleTime !== undefined) {result = result.setStaleTime(config.staleTime);}
|
|
169
|
+
if (config.retry !== undefined) {result = result.setRetry(config.retry);}
|
|
170
|
+
if (config.retryTime !== undefined) {result = result.setRetryTime(config.retryTime);}
|
|
171
|
+
if (config.cancelable !== undefined) {result = result.setCancelable(config.cancelable);}
|
|
172
|
+
if (config.queued !== undefined) {result = result.setQueued(config.queued);}
|
|
173
|
+
if (config.offline !== undefined) {result = result.setOffline(config.offline);}
|
|
174
|
+
if (config.deduplicate !== undefined) {result = result.setDeduplicate(config.deduplicate);}
|
|
133
175
|
if (config.deduplicateTime !== undefined && config.deduplicateTime !== null) {
|
|
134
176
|
result = result.setDeduplicateTime(config.deduplicateTime);
|
|
135
177
|
}
|
|
@@ -141,7 +183,7 @@ const applyDefaults = (
|
|
|
141
183
|
context: { endpoint: string; sdkPath: string; defaults?: Partial<Record<string, SdkConfigurationValue>> },
|
|
142
184
|
): RequestInstance => {
|
|
143
185
|
const { endpoint, sdkPath, defaults } = context;
|
|
144
|
-
if (!defaults) return request;
|
|
186
|
+
if (!defaults) {return request;}
|
|
145
187
|
|
|
146
188
|
let result = request;
|
|
147
189
|
const entries = Object.entries(defaults);
|
|
@@ -153,7 +195,7 @@ const applyDefaults = (
|
|
|
153
195
|
|
|
154
196
|
for (let i = 0; i < entries.length; i += 1) {
|
|
155
197
|
const [key, value] = entries[i];
|
|
156
|
-
if (!value) continue;
|
|
198
|
+
if (!value) {continue;}
|
|
157
199
|
const entry: [string, SdkConfigurationValue] = [key, value];
|
|
158
200
|
if (entry[0] === "*") {
|
|
159
201
|
globalEntries.push(entry);
|
|
@@ -197,7 +239,7 @@ const createRecursiveProxy = (
|
|
|
197
239
|
return new Proxy(() => {}, {
|
|
198
240
|
get: (_target, key: string) => {
|
|
199
241
|
if (typeof key === "symbol" || key === "inspect") {
|
|
200
|
-
return
|
|
242
|
+
return;
|
|
201
243
|
}
|
|
202
244
|
|
|
203
245
|
// Check if this is a method (starts with $) or a path segment
|
|
@@ -210,7 +252,7 @@ const createRecursiveProxy = (
|
|
|
210
252
|
methodName = key.slice(1);
|
|
211
253
|
pathSegment = `:${key.slice(1)}`;
|
|
212
254
|
} else if (options?.camelCaseToKebabCase) {
|
|
213
|
-
pathSegment = key.
|
|
255
|
+
pathSegment = key.replaceAll(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
|
|
214
256
|
}
|
|
215
257
|
|
|
216
258
|
// Build the sdk dot-path for method-specific configuration matching
|
|
@@ -231,7 +273,11 @@ const createRecursiveProxy = (
|
|
|
231
273
|
return new Proxy(request, {
|
|
232
274
|
get: (reqTarget, reqKey: string) => {
|
|
233
275
|
// If the property exists on the request instance (like .send(), .setParams()), return it.
|
|
234
|
-
|
|
276
|
+
// Optional fields are checked by name as well: transpilers that compile class
|
|
277
|
+
// properties in loose mode (Metro on React Native) drop uninitialized field
|
|
278
|
+
// declarations, and falling through to the deeper proxy would hand callers a
|
|
279
|
+
// truthy path proxy where they expect undefined.
|
|
280
|
+
if (reqKey in reqTarget || (OPTIONAL_REQUEST_FIELDS as readonly string[]).includes(reqKey)) {
|
|
235
281
|
return reqTarget[reqKey as keyof typeof reqTarget];
|
|
236
282
|
}
|
|
237
283
|
// Otherwise, it's a deeper path, so delegate to the deeper proxy.
|
|
@@ -242,18 +288,28 @@ const createRecursiveProxy = (
|
|
|
242
288
|
});
|
|
243
289
|
};
|
|
244
290
|
|
|
245
|
-
|
|
291
|
+
/**
|
|
292
|
+
* The fully-resolved SDK instance type returned by `createSdk`.
|
|
293
|
+
*
|
|
294
|
+
* The schema is rewritten via {@link InjectClient} so every `Request` leaf carries the
|
|
295
|
+
* actual client type passed to `createSdk(client)` - users do not need to repeat
|
|
296
|
+
* `client: AppClient` in every `RequestModel<{...}>` declaration.
|
|
297
|
+
*/
|
|
298
|
+
export type SdkInstance<
|
|
299
|
+
Schema extends RecursiveSchemaType,
|
|
300
|
+
TClient extends ClientInstance = ClientInstance,
|
|
301
|
+
> = InjectClient<Schema, TClient> & {
|
|
246
302
|
/**
|
|
247
303
|
* Apply request defaults to the SDK. Returns a new SDK instance with the configuration applied.
|
|
248
304
|
* Use "*" to match all endpoints, or specific endpoint strings / wildcard patterns.
|
|
249
305
|
*/
|
|
250
|
-
$configure: (defaults: SdkConfigurationMap<Schema>) => SdkInstance<Schema>;
|
|
306
|
+
$configure: (defaults: SdkConfigurationMap<Schema>) => SdkInstance<Schema, TClient>;
|
|
251
307
|
};
|
|
252
308
|
|
|
253
309
|
export const createSdk = <Client extends ClientInstance, RecursiveSchema extends RecursiveSchemaType>(
|
|
254
310
|
client: Client,
|
|
255
311
|
options?: CreateSdkOptions<RecursiveSchema>,
|
|
256
|
-
): SdkInstance<RecursiveSchema> => {
|
|
312
|
+
): SdkInstance<RecursiveSchema, Client> => {
|
|
257
313
|
const {
|
|
258
314
|
camelCaseToKebabCase = true,
|
|
259
315
|
methodTransform = (method: string) => method.toUpperCase(),
|
|
@@ -277,7 +333,7 @@ export const createSdk = <Client extends ClientInstance, RecursiveSchema extends
|
|
|
277
333
|
}
|
|
278
334
|
return target[key];
|
|
279
335
|
},
|
|
280
|
-
}) as SdkInstance<RecursiveSchema>;
|
|
336
|
+
}) as SdkInstance<RecursiveSchema, Client>;
|
|
281
337
|
};
|
|
282
338
|
|
|
283
339
|
/**
|
package/src/types/http.types.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export type HttpMethodsType = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
1
|
+
export type HttpMethodsType = "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "QUERY";
|
|
2
2
|
export type HttpStatusType = number;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { ResponseType } from "adapter";
|
|
2
|
+
import type { Client, ClientInstance } from "client";
|
|
2
3
|
import type { ExtractUrlParams, Request, RequestInstance } from "request";
|
|
4
|
+
|
|
5
|
+
import type { ExtractAdapterEndpointType } from "./adapter.types";
|
|
3
6
|
import type { ExtractClientAdapterType, ExtractClientGlobalError } from "./client.types";
|
|
4
|
-
import type { Client, ClientInstance } from "client";
|
|
5
7
|
import type { TypeWithDefaults } from "./helpers.types";
|
|
6
|
-
import type { ExtractAdapterEndpointType } from "./adapter.types";
|
|
7
8
|
|
|
8
9
|
export type ExtractAdapterResolvedType<T extends RequestInstance> = ResponseType<
|
|
9
10
|
ExtractResponseType<T>,
|
|
@@ -3,7 +3,7 @@ import Emitter from "events";
|
|
|
3
3
|
const getListenName = (event: string | symbol) => `listen_${String(event)}`;
|
|
4
4
|
|
|
5
5
|
export class EventEmitter extends Emitter {
|
|
6
|
-
emitCallbacks:
|
|
6
|
+
emitCallbacks: ((event: string, data: any, isTriggeredExternally?: true) => void)[] = [];
|
|
7
7
|
|
|
8
8
|
// eslint-disable-next-line @typescript-eslint/no-useless-constructor
|
|
9
9
|
constructor(options?: ConstructorParameters<typeof Emitter>[0]) {
|
package/src/utils/uuid.utils.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { RequestInstance } from "request";
|
|
2
2
|
|
|
3
3
|
export const getUniqueRequestId = (request: Pick<RequestInstance, "queryKey">) => {
|
|
4
|
-
return `${request.queryKey}_${Date.now().toString(36)}_${Math.random().toString(36).
|
|
4
|
+
return `${request.queryKey}_${Date.now().toString(36)}_${Math.random().toString(36).slice(2)}`;
|
|
5
5
|
};
|
package/tsconfig.json
CHANGED
|
@@ -1,10 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"extends": "../../tsconfig.json",
|
|
3
3
|
"compilerOptions": {
|
|
4
|
-
"
|
|
4
|
+
"types": ["node"],
|
|
5
5
|
"paths": {
|
|
6
|
-
"
|
|
6
|
+
"adapter": ["./src/adapter"],
|
|
7
|
+
"adapter/*": ["./src/adapter/*"],
|
|
8
|
+
"cache": ["./src/cache"],
|
|
9
|
+
"cache/*": ["./src/cache/*"],
|
|
10
|
+
"client": ["./src/client"],
|
|
11
|
+
"client/*": ["./src/client/*"],
|
|
12
|
+
"constants": ["./src/constants"],
|
|
13
|
+
"constants/*": ["./src/constants/*"],
|
|
14
|
+
"dispatcher": ["./src/dispatcher"],
|
|
15
|
+
"dispatcher/*": ["./src/dispatcher/*"],
|
|
16
|
+
"http-adapter": ["./src/http-adapter"],
|
|
17
|
+
"http-adapter/*": ["./src/http-adapter/*"],
|
|
18
|
+
"managers": ["./src/managers"],
|
|
19
|
+
"managers/*": ["./src/managers/*"],
|
|
20
|
+
"mocker": ["./src/mocker"],
|
|
21
|
+
"mocker/*": ["./src/mocker/*"],
|
|
22
|
+
"plugin": ["./src/plugin"],
|
|
23
|
+
"plugin/*": ["./src/plugin/*"],
|
|
24
|
+
"request": ["./src/request"],
|
|
25
|
+
"request/*": ["./src/request/*"],
|
|
26
|
+
"sdk": ["./src/sdk"],
|
|
27
|
+
"sdk/*": ["./src/sdk/*"],
|
|
28
|
+
"types": ["./src/types"],
|
|
29
|
+
"types/*": ["./src/types/*"],
|
|
30
|
+
"utils": ["./src/utils"],
|
|
31
|
+
"utils/*": ["./src/utils/*"],
|
|
32
|
+
"index": ["./src/index"],
|
|
33
|
+
"@hyper-fetch/core": ["./src"]
|
|
7
34
|
}
|
|
8
35
|
},
|
|
36
|
+
"include": ["src/**/*.ts", "../../global.d.ts"],
|
|
9
37
|
"exclude": ["node_modules", "dist", "vite.config.ts", "__tests__"]
|
|
10
38
|
}
|
package/vite.config.ts
CHANGED
|
@@ -1,45 +1,39 @@
|
|
|
1
1
|
/// <reference types="vitest/config" />
|
|
2
|
+
import path from "path";
|
|
2
3
|
import { defineConfig } from "vite";
|
|
3
4
|
import dts from "vite-plugin-dts";
|
|
4
5
|
import tsconfigPaths from "vite-tsconfig-paths";
|
|
5
|
-
|
|
6
|
-
import { getDtsCompilerOptionsForPackage } from "../../scripts/vite-dts-internal-paths";
|
|
6
|
+
|
|
7
7
|
import { getRollupExternalsFromPackageJson } from "../../scripts/vite-lib-externals-from-package";
|
|
8
8
|
|
|
9
9
|
export default defineConfig({
|
|
10
10
|
build: {
|
|
11
11
|
lib: {
|
|
12
12
|
entry: "src/index.ts",
|
|
13
|
-
formats: ["es"],
|
|
14
13
|
fileName: "index",
|
|
14
|
+
formats: ["es"],
|
|
15
15
|
},
|
|
16
|
-
sourcemap: true,
|
|
17
16
|
minify: false,
|
|
18
17
|
rollupOptions: {
|
|
19
18
|
external: getRollupExternalsFromPackageJson(__dirname),
|
|
20
19
|
},
|
|
20
|
+
sourcemap: true,
|
|
21
21
|
},
|
|
22
|
-
plugins: [
|
|
23
|
-
dts({
|
|
24
|
-
entryRoot: "src",
|
|
25
|
-
compilerOptions: getDtsCompilerOptionsForPackage(__dirname),
|
|
26
|
-
}),
|
|
27
|
-
tsconfigPaths(),
|
|
28
|
-
],
|
|
22
|
+
plugins: [tsconfigPaths(), dts({ entryRoot: "src" })],
|
|
29
23
|
test: {
|
|
30
|
-
globals: true,
|
|
31
|
-
environment: "jsdom",
|
|
32
|
-
setupFiles: ["./__tests__/vitest.setup.ts"],
|
|
33
|
-
include: ["__tests__/**/*.spec.{ts,tsx}", "src/**/*.spec.{ts,tsx}"],
|
|
34
|
-
coverage: {
|
|
35
|
-
provider: "v8",
|
|
36
|
-
include: ["src/**/*.{ts,tsx}"],
|
|
37
|
-
exclude: ["**/*.spec.*", "**/types.*", "**/constants.*", "**/index.ts"],
|
|
38
|
-
},
|
|
39
24
|
alias: {
|
|
40
25
|
"@hyper-fetch/core": path.resolve(__dirname, "./src/index.ts"),
|
|
41
26
|
"@hyper-fetch/sockets": path.resolve(__dirname, "../sockets/src/index.ts"),
|
|
42
27
|
"@hyper-fetch/testing": path.resolve(__dirname, "../testing/src/index.ts"),
|
|
43
28
|
},
|
|
29
|
+
coverage: {
|
|
30
|
+
exclude: ["**/*.spec.*", "**/types.*", "**/constants.*", "**/index.ts"],
|
|
31
|
+
include: ["src/**/*.{ts,tsx}"],
|
|
32
|
+
provider: "v8",
|
|
33
|
+
},
|
|
34
|
+
environment: "jsdom",
|
|
35
|
+
globals: true,
|
|
36
|
+
include: ["__tests__/**/*.spec.{ts,tsx}", "src/**/*.spec.{ts,tsx}"],
|
|
37
|
+
setupFiles: ["./__tests__/vitest.setup.ts"],
|
|
44
38
|
},
|
|
45
39
|
});
|
package/.eslintrc.cjs
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
extends: ["plugin:@nx/react", "../../.eslintrc.js"],
|
|
3
|
-
parserOptions: {
|
|
4
|
-
tsconfigRootDir: __dirname,
|
|
5
|
-
project: ["./tsconfig.json", "./__tests__/tsconfig.json"],
|
|
6
|
-
},
|
|
7
|
-
rules: {
|
|
8
|
-
"react/jsx-props-no-spreading": 0,
|
|
9
|
-
"react/require-default-props": 0,
|
|
10
|
-
},
|
|
11
|
-
ignorePatterns: ["dist/", "coverage/", "vite.config.ts", "/*.js"],
|
|
12
|
-
};
|